Skip to content

Instantly share code, notes, and snippets.

@naftulikay
Last active November 7, 2022 21:44
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save naftulikay/7bcf6d0ed1d41cfb81d72a7d32981c33 to your computer and use it in GitHub Desktop.
Save naftulikay/7bcf6d0ed1d41cfb81d72a7d32981c33 to your computer and use it in GitHub Desktop.
Sync a directory to S3 and invalidate the CloudFront cache for changed resources.
#!/bin/bash
# output format is like this:
# upload: index.html to s3://$BUCKET/index.html
#
# so we grab the second item which is the file path and pass that via xargs to the
# cloudfront invalidation command
aws s3 sync --sse AES256 s3://$BUCKET/ site/ | awk '{print $2;}' | \
xargs aws cloudfront create-invalidation --distribution-id $CF_DISTRO_ID --paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment