Skip to content

Instantly share code, notes, and snippets.

@leesmith
Created October 9, 2019 17:15
Show Gist options
  • Save leesmith/181dec1332a3c262f4d8a948a0afa4e1 to your computer and use it in GitHub Desktop.
Save leesmith/181dec1332a3c262f4d8a948a0afa4e1 to your computer and use it in GitHub Desktop.
Sync Nuxtjs dist folder to S3 and invalidate Cloudfront distribution
#!/usr/bin/env bash
#
# Sync generated site to S3 and invalidate Cloudfront distribution
if [ ! -f .env ]; then
echo "# Project environment variables...do not commit this file." >> .env
echo "AWS_CF_DIST_ID=" >> .env
echo "AWS_S3_URI=" >> .env
echo "Please add the necessary values to the .env file."
else
export $(egrep -v '^#' .env | xargs)
echo "CF DIST -> $AWS_CF_DIST_ID"
echo "S3 URI -> $AWS_S3_URI"
echo "Performing sync..."
aws s3 sync dist s3://$AWS_S3_URI --cache-control "max-age=31536000, immutable" --delete
aws s3 cp dist/index.html s3://$AWS_S3_URI/index.html --cache-control "no-cache"
echo "Invalidating cloudfront distribution..."
aws cloudfront create-invalidation --distribution-id $AWS_CF_DIST_ID --paths "/*"
echo "Deploy complete! 🎉"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment