Created
May 21, 2017 17:28
-
-
Save pram/ca1e7010024e347a3a1bd345ea0f43a3 to your computer and use it in GitHub Desktop.
Cloudfront cache invalidate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SETLOCAL | |
SET DISTRIBUTION_ID= :: Set your distribution id here, it looks like a random string A3JF7TKL2VRF7X | |
SET BUCKET_NAME= ::PUT YORU BUCKET NAME HERE | |
hugo -v | |
:: Copy over pages - not static js/img/css/downloads | |
::--profile lauf | |
aws s3 sync --acl "public-read" --sse "AES256" public/ s3://%BUCKET_NAME%/ --exclude 'img' --exclude 'js' --exclude 'downloads' --exclude 'css' --exclude 'post' | |
:: Ensure static files are set to cache forever - cache for a month --cache-control "max-age=2592000" | |
aws s3 sync --cache-control "max-age=2592000" --acl "public-read" --sse "AES256" public/img/ s3://%BUCKET_NAME%/img/ | |
aws s3 sync --cache-control "max-age=2592000" --acl "public-read" --sse "AES256" public/css/ s3://%BUCKET_NAME%/css/ | |
aws s3 sync --cache-control "max-age=2592000" --acl "public-read" --sse "AES256" public/js/ s3://%BUCKET_NAME%/js/ | |
:: Downloads binaries, not part of repo - cache at edge for a year --cache-control "max-age=31536000" | |
aws s3 sync --cache-control "max-age=31536000" --acl "public-read" --sse "AES256" static/downloads/ s3://%BUCKET_NAME%/downloads/ | |
:: Invalidate landing page so everything sees new post - warning, first 1K/mo free, then 1/2 cent ea | |
aws cloudfront create-invalidation --distribution-id %DISTRIBUTION_ID% --paths /index.html / | |
ENDLOCAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From https://www.reddit.com/r/startups/comments/6aqxfx/whatre_the_cheapest_hasslefree_options_for_static/dhh3uwj/