Skip to content

Instantly share code, notes, and snippets.

@kremalicious
Created February 26, 2020 22:32
Show Gist options
  • Save kremalicious/ff1e632a4926110d51eec048a0982b4d to your computer and use it in GitHub Desktop.
Save kremalicious/ff1e632a4926110d51eec048a0982b4d to your computer and use it in GitHub Desktop.
Deploying a Gatsby.js site to S3 with correct caching headers
#!/usr/bin/env bash
#
# required environment variables:
# AWS_ACCESS_KEY_ID
# AWS_SECRET_ACCESS_KEY
# AWS_DEFAULT_REGION
AWS_S3_BUCKET="bucket-name"
function s3sync {
aws s3 sync ./public s3://"$1" \
--include "*" \
--exclude "*.html" \
--exclude "sw.js" \
--exclude "*page-data.json" \
--exclude "*app-data.json" \
--exclude "chunk-map.json" \
--exclude "sitemap.xml" \
--exclude ".iconstats.json" \
--exclude "humans.txt" \
--exclude "robots.txt" \
--cache-control public,max-age=31536000,immutable \
--delete \
--acl public-read
aws s3 sync ./public s3://"$1" \
--exclude "*" \
--include "*.html" \
--include "sw.js" \
--include "*page-data.json" \
--include "*app-data.json" \
--include "chunk-map.json" \
--include "sitemap.xml" \
--include ".iconstats.json" \
--include "humans.txt" \
--include "robots.txt" \
--cache-control public,max-age=0,must-revalidate \
--delete \
--acl public-read
}
s3sync $AWS_S3_BUCKET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment