
If you have hosted your angular app to AWS S3 then you can automate your ng build -prod and drag and drop to S3 bucket by simply following below steps -
Step 1 - Add @jefiozie/ngx-aws-deploy to your project and for this run below command (your angular CLI should be up-to-date)
Code: Select all
ng add @jefiozie/ngx-aws-deploy
You will be prompted for a couple of questions:
Your AWS Region
The bucket you would like the files to be uploaded.
The Secret Access Key
The Access key Id
The folder where the files should be uploaded (optional)
Step 3 - Verify the details you have provided is correct, open angular.json and search for deploy and should be able to see below code -
Code: Select all
angular.json is update with a new builder:
"deploy": {
"builder": "@jefiozie/ngx-aws-deploy:deploy",
"options": {
"region": "YOUR REGION",
"bucket": "YOUR BUCKET",
"secretAccessKey": "YOUR SECRET ACCESSKEY",
"accessKeyId": "YOUR ACCESS KEY ID"
}
Step 4 - Run ng deploy command and it will build and deploy your app to S3.
All Done
Extra Bits-
If after following all above steps you run into trouble and get below error -
Code: Select all
403 Forbidden
Code: AccessDenied
Message: Access Denied
Code: Select all
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::your-bucket-name-here/*"
]
}
]
}
All done, refresh the page and your app will up and running.