Last active
November 13, 2018 15:52
-
-
Save aindong/6ce09ef005d3e6dbf00451933c6a4f1c to your computer and use it in GitHub Desktop.
React-S3-CloudFront Deployment Shell Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "Stmt1489770487230", | |
"Effect": "Allow", | |
"Principal": { | |
"AWS": "arn user" | |
}, | |
"Action": [ | |
"s3:PutObject", | |
"s3:PutObjectAcl", | |
"s3:GetObject", | |
"s3:DeleteObject" | |
], | |
"Resource": "arn:aws:s3:::bucket-name/*" | |
}, | |
{ | |
"Sid": "Stmt1489770522510", | |
"Effect": "Allow", | |
"Principal": { | |
"AWS": "arn" | |
}, | |
"Action": "s3:ListBucket", | |
"Resource": "arn:aws:s3:::bucket-name" | |
}, | |
{ | |
"Sid": "PublicReadGetObject", | |
"Effect": "Allow", | |
"Principal": "*", | |
"Action": "s3:GetObject", | |
"Resource": "arn:aws:s3:::bucket-name/*" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BUCKETNAME= | |
AWS_PROFILE= | |
GIT_BRANCH= | |
CLOUDFRONT_ID= | |
git checkout $GIT_BRANCH | |
git pull origin $GIT_BRANCH | |
npm run build | |
aws s3 sync build s3://$BUCKETNAME --delete --cache-control max-age=604800,public --profile $AWS_PROFILE | |
aws s3 cp s3://$BUCKETNAME/service-worker.js s3://$BUCKETNAME/service-worker.js --metadata-directive REPLACE --cache-control max-age=0,no-cache,no-store,must-revalidate --content-type application/javascript --acl public-read --profile $AWS_PROFILE | |
aws s3 cp s3://$BUCKETNAME/index.html s3://$BUCKETNAME/index.html --metadata-directive REPLACE --cache-control max-age=0,no-cache,no-store,must-revalidate --content-type text/html --acl public-read --profile $AWS_PROFILE | |
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths /index.html --profile $AWS_PROFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment