Skip to content

Instantly share code, notes, and snippets.

@petrabarus
Last active April 18, 2022 04:31
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 petrabarus/dfa7e7639bbc630c502b8e932f8da4fe to your computer and use it in GitHub Desktop.
Save petrabarus/dfa7e7639bbc630c502b8e932f8da4fe to your computer and use it in GitHub Desktop.
Invalidate CloudFront Distribution and Wait
#!/usr/bin/env bash
# Requirements
# - AWS
# - jq
# Variables
PROFILE=
DISTRIBUTION_ID=
PATHS="/*"
# Check required dependencies
aws --version && jq --version
# Invalidate
echo "Invalidating $DISTRIBUTION_ID"
OUTPUT=$(aws --profile $PROFILE cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths $PATH)
echo "Invalidation Created."
echo $OUTPUT | jq -r
INVALIDATION_ID=$(echo $OUTPUT | jq -r '.Invalidation.Id')
echo "Invalidation ID: $INVALIDATION_ID"
# Wait until complete
echo "Waiting..."
aws --profile $PROFILE cloudfront wait invalidation-completed --distribution-id $DISTRIBUTION_ID --id $INVALIDATION_ID
echo "Completed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment