Created
April 27, 2022 15:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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