Created
April 27, 2022 15:22
-
-
Save joshbeard/5de66179be2c3d6b2ab49ceafb390844 to your computer and use it in GitHub Desktop.
GitLab CloudFront Cache Invalidation example
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 Cache Invalidation | |
# ------------------------------------------------------------------------------ | |
.cf_invalidate: | |
image: | |
name: amazon/aws-cli:latest | |
entrypoint: [""] | |
stage: CloudFront | |
when: manual | |
tags: | |
- prod | |
script: | |
# 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 "/*" | |
only: | |
variables: | |
- $CI_COMMIT_REF_PROTECTED == "true" | |
refs: | |
- release | |
cache_invalidate:beta: | |
extends: .cf_invalidate | |
variables: | |
CLOUDFRONT_HOST: beta.foo.com | |
cache_invalidate:prod: | |
extends: .cf_invalidate | |
variables: | |
CLOUDFRONT_HOST: foo.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment