Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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