Skip to content

Instantly share code, notes, and snippets.

@joshbeard
Created April 27, 2022 15:19
Show Gist options
  • Save joshbeard/0763588c61df2b807eb357e6de940dce to your computer and use it in GitHub Desktop.
Save joshbeard/0763588c61df2b807eb357e6de940dce to your computer and use it in GitHub Desktop.
CloudFront cache invalidate that looks up the distribution ID based on the alias
CLOUDFRONT_HOST=foo.gov
# Get the CloudFront distribution ID based on the host name (CLOUDFRONT_HOST)
cfid=$(aws cloudfront list-distributions --query "DistributionList.Items[].{id: Id,cf_domain: DomainName, aliases: Aliases.Items[0]}[?contains(aliases, '${CLOUDFRONT_HOST}')] | [0].id" --output text)
# Invalidate the cache
aws cloudfront create-invalidation --distribution-id "$cfid" --paths "/one/* /two/*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment