Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deploy React app to s3/cloudfront
#!/bin/bash
if [ "$1" == "staging" ]; then
NODE_ENV="staging"
ENV="staging"
S3_URL="s3://your-staging-bucket"
CLOUDFRONT_ID="XXX-STAGING-ID"
echo "[🔨 Deploy] Building project"
npm run build:staging
elif [ "$1" == "production" ]; then
NODE_ENV="production"
ENV="production"
S3_URL="s3://your-prod-bucket"
CLOUDFRONT_ID="XXX-PROD-ID"
echo "[🔨 Deploy] Building project"
npm run build
else
echo "Usage ./bin/deploy {staging|production}" && exit 1;
fi
echo "[☁️ Deploy] Deploying to s3"
aws s3 sync build $S3_URL
echo "[🌎 Deploy] Clearing app cache"
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*" > /dev/null
echo "[🚀 Deploy] Successfully deployed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment