Skip to content

Instantly share code, notes, and snippets.

@mealies
Last active April 10, 2019 06:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mealies/768b6c95b39a5d35085595f09383c100 to your computer and use it in GitHub Desktop.
Save mealies/768b6c95b39a5d35085595f09383c100 to your computer and use it in GitHub Desktop.
Deply hugo static site to AWS s3
#!/bin/bash
set -e
DISTRIBUTION_ID=E1TOB0026XX0U7
BUCKET_NAME=thatopsguy.com
hugo -v
# Copy over pages
aws s3 sync --acl "public-read" --sse "AES256" public/ s3://$BUCKET_NAME/ --exclude 'img' --exclude 'js' --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/
# Invalidate landing page so everything sees new post.
aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /index.html /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment