Skip to content

Instantly share code, notes, and snippets.

@tboock
Created January 6, 2020 13:27
Show Gist options
  • Select an option

  • Save tboock/943923d00e6dbf5a608bec16e210fa2b to your computer and use it in GitHub Desktop.

Select an option

Save tboock/943923d00e6dbf5a608bec16e210fa2b to your computer and use it in GitHub Desktop.
Enable client-side caching for files *after* deployment. Useful if you are hit by https://github.com/aws/aws-cdk/issues/4665.
#!/usr/bin/env bash
function enable_caching {
ttl="$1"
shift
for dir in "${@}"
do
aws s3 cp \
--metadata-directive REPLACE \
--cache-control "max-age=$ttl" \
--recursive \
"s3://some-bucket/$dir/" \
"s3://some-bucket/$dir/"
done
}
enable_caching 86400 "css" "js"
enable_caching 31536000 "fonts" "img"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment