Skip to content

Instantly share code, notes, and snippets.

@jcyuyi
Created December 11, 2018 04:53
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 jcyuyi/3adfe1574f1e756798300c0dc2fd5ea3 to your computer and use it in GitHub Desktop.
Save jcyuyi/3adfe1574f1e756798300c0dc2fd5ea3 to your computer and use it in GitHub Desktop.
Deploy Hugo to S3 with CloudFront invalidation
#!/usr/bin/env bash
if [[ "$#" -ne 3 ]]; then
echo "Illegal number of parameters"
echo "Usage: deploy BASE_URL S3_URL DISTRIBUTION_ID"
exit 1
fi
# Base URL
BASE_URL=$1
# S3 URL
S3_URL=$2
# CloudFront DISTRIBUTION ID
DISTRIBUTION_ID=$3
echo "Building ${BASE_URL}..."
# The command `hugo` renders your site into `public/` dir and is ready to be deployed to your web server.
hugo --baseURL ${BASE_URL}
echo "Uploading ${S3_URL}..."
aws s3 cp public ${S3_URL} --recursive
echo "Refreshing ${DISTRIBUTION_ID}..."
aws cloudfront create-invalidation \
--distribution-id ${DISTRIBUTION_ID} \
--paths '/*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment