Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/Jefiozie/ngx-aws-deploy

☁️🚀 Deploy your Angular app to Amazon S3 directly from the Angular CLI 🚀☁️
https://github.com/Jefiozie/ngx-aws-deploy

amazon angular aws builder deploy hacktoberfest

Last synced: 2 months ago
JSON representation

☁️🚀 Deploy your Angular app to Amazon S3 directly from the Angular CLI 🚀☁️

Lists

README

        

# NGX-AWS-DEPLOY

☁️🚀 Deploy your Angular app to Amazon S3 directly from the Angular CLI 🚀☁️

[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)

![CI](https://github.com/Jefiozie/ngx-aws-deploy/workflows/Publish/badge.svg)
![npm](https://img.shields.io/npm/dw/@jefiozie/ngx-aws-deploy)
![npm (scoped)](https://img.shields.io/npm/v/@jefiozie/ngx-aws-deploy)
![GitHub issues](https://img.shields.io/github/issues/jefiozie/ngx-aws-deploy)




Twitter Follow


ngx-aws-deploy

## Quick Start

1. Install the latest version of Angular cli

```sh
yarn global add @angular/cli
```

2. Create a new Angular project
```sh
ng new hello-world --defaults
cd hello-world
```
3. Add `@jefiozie/ngx-aws-deploy` to your project

```sh
ng add @jefiozie/ngx-aws-deploy
```

4. After these steps your `angular.json` is updated with a new builder:

```json
"deploy": {
"builder": "@jefiozie/ngx-aws-deploy:deploy",
"options": {}
}
```

5. Due to security risk we have made the decision to never add any options to the `angular.json`. You should set the environments variable during the `ng deploy` command. Below is an example on how you could do this.

```bash
npx cross-env NG_DEPLOY_AWS_ACCESS_KEY_ID=1234 NG_DEPLOY_AWS_SECRET_ACCESS_KEY=321ACCESS NG_DEPLOY_AWS_BUCKET=mys3bucket NG_DEPLOY_AWS_REGION=eu-1-region NG_DEPLOY_AWS_SUB_FOLDER=path/on/bucker ng deploy
```

6. To trigger an optional invalidation of the files in an AWS CloudFront distribution, add these parameters to the above command line:

```
npx cross-env ... NG_DEPLOY_AWS_CF_DISTRIBUTION_ID=1234 ... ng deploy
```

7. To apply properties on uploaded files, use the `NG_DEPLOY_AWS_GLOB_FILE_UPLOAD_PARAMS_LIST` variable or the target option `globFileUploadParamsList` as shown below.
We use an array of objects to represent the different configurations.
Each config object needs a `glob` property to define on which files the params will be set.
Other properties on the config object are the params to apply.
For informations about the possible params (ACL, Bucket, CacheControl, etc), checkout the documentation of the `s3.upload` method (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property)

```json
"deploy": {
"builder": "@jefiozie/ngx-aws-deploy:deploy",
"options": {
"globFileUploadParamsList": [
{
"glob": "*",
"ACL": "public-read",
"CacheControl": "max-age=3600"
},
{
"glob": "*.html",
"CacheControl": "max-age=300"
}
]
}
},
```

The order of the config objects matters, the one that comes last is the one that will be used, as shown above:

- CacheControl is set for all files but it's overidden by the next config object only for html files. Convenient for declaring exceptions and not repeat global settings.

To set this using the environment variable `NG_DEPLOY_AWS_GLOB_FILE_UPLOAD_PARAMS_LIST`, simply stringify the config object to JSON with `JSON.stringify`.

```bash
npx cross-env ... NG_DEPLOY_AWS_GLOB_FILE_UPLOAD_PARAMS_LIST='[{"glob":"*","ACL":"public-read","CacheControl":"max-age=3600"},{"glob":"*.html","CacheControl":"max-age=300"}]' ... ng deploy
```

8. Run `ng deploy` to deploy your application to Amazon S3.

🚀**_Happy deploying!_** 🚀

## Security 🔑

Keep in mind that **with the default config, everybody that has access to the angular.json will have your aws secret**.
If you want more security, you can also use environment variable with `NG_DEPLOY_AWS_ACCESS_KEY_ID`, `NG_DEPLOY_AWS_SECRET_ACCESS_KEY`, `NG_DEPLOY_AWS_BUCKET` and `NG_DEPLOY_AWS_REGION`.

#### Minimal Required IAM Policy for AWS Credentials

```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::$BUCKET_NAME$"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::$BUCKET_NAME$/*"
]
}
]
}
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
The builder is located in the `libs\ngx-aws-deploy`folder.
The sample app is located in the `apps\demo-app` folder.
Please make sure to update tests as appropriate.

## License

[MIT](./LICENSE)

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Jeffrey Bosch

💻 🖋 👀

Santosh Yadav

💻

Nicolas Beaussart

💻

Stefan Nieuwenhuis

💻

Zack Yang

💻

David Houseknecht

📖

Brian Harris

📖



Michael Vogl

💻

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!