Skip to content

Instantly share code, notes, and snippets.

@aindong
Last active November 13, 2018 15:52
Show Gist options
  • Save aindong/6ce09ef005d3e6dbf00451933c6a4f1c to your computer and use it in GitHub Desktop.
Save aindong/6ce09ef005d3e6dbf00451933c6a4f1c to your computer and use it in GitHub Desktop.
React-S3-CloudFront Deployment Shell Script
{
"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/*"
}
]
}
#!/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