Created
December 19, 2021 18:09
-
-
Save m-nathani/178d4e38549d8d42d3a9dc42fe30c475 to your computer and use it in GitHub Desktop.
Deployment to AWS S3 of create-react-app builds
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 | |
if [[ "$1" != "" ]]; then | |
S3BUCKETNAME="$1" | |
else | |
echo ERROR: Failed to supply S3 bucket name | |
exit 1 | |
fi | |
# Sync root folder with no-cache control, excluding the static while which will be cache busted with new hash names by CRA build | |
aws s3 sync build/ s3://$S3BUCKETNAME \ | |
--cache-control no-cache \ | |
--exclude 'static/*' \ | |
--delete | |
# Sync static folder with a long max-age cache-control | |
aws s3 sync build/static/ s3://$S3BUCKETNAME/static \ | |
--cache-control max-age=31536000 \ | |
--delete |
How to use
./s3-sync.sh "s3-bucket-name"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chore(deployment): fix cache issue on deployment with s3 sync script
BREAKING CHANGE:
update aws s3 deployment strategy
ISSUES CLOSED:
fix cache issues to make full use of CDN such as cloudfront to cache files...