Skip to content

Instantly share code, notes, and snippets.

@m-nathani
Created December 19, 2021 18:09
Show Gist options
  • Save m-nathani/178d4e38549d8d42d3a9dc42fe30c475 to your computer and use it in GitHub Desktop.
Save m-nathani/178d4e38549d8d42d3a9dc42fe30c475 to your computer and use it in GitHub Desktop.
Deployment to AWS S3 of create-react-app builds
#!/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
@m-nathani
Copy link
Author

m-nathani commented Dec 19, 2021

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...

@m-nathani
Copy link
Author

m-nathani commented Dec 19, 2021

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