Skip to content

Instantly share code, notes, and snippets.

@Daveiano
Created January 21, 2019 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daveiano/1862a4773e47ceaa9f8a35188b0e7357 to your computer and use it in GitHub Desktop.
Save Daveiano/1862a4773e47ceaa9f8a35188b0e7357 to your computer and use it in GitHub Desktop.
Basic Sync Script for AWS S3 for a static website bucket with Cloudfront Cache invalidation
#!/bin/bash
# Should be in Format: Wed, 21 Oct 2015 07:28:00 GMT
expire_date=$(date +"%a, %d %b %Y 16:00:00 GMT" -d '+ 1 month')
# Sync Assets, max-age = 1 month, expires header set now + 1 month
aws s3 sync ./.. s3://<bucket> --exclude '*' --include 'favicon.ico' --include 'dist/*' --include 'index.html' --cache-control 'public, max-age=2592000' --expires "$expire_date" --delete
# Cloudfront Cache Invalidation
aws cloudfront create-invalidation --distribution-id <ID> --paths '/*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment