Skip to content

Instantly share code, notes, and snippets.

@rowanu
Created January 13, 2020 23:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowanu/54c27d744ddad4c4d98ba62665f782d5 to your computer and use it in GitHub Desktop.
Save rowanu/54c27d744ddad4c4d98ba62665f782d5 to your computer and use it in GitHub Desktop.
Invalidate CloudFront from CodePipeline
InvalidateCacheProject:
Type: AWS::CodeBuild::Project
Properties:
Artifacts:
Type: CODEPIPELINE
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:2.0
Type: LINUX_CONTAINER
Name: !Sub ${AWS::StackName}-invalidate-cache
ServiceRole: !GetAtt InvalidateCacheRole.Arn
Source:
Type: CODEPIPELINE
BuildSpec: |
version: 0.2
env:
parameter-store:
# NOTE: Using here avoids circular dependency
DISTRIBUTION_ID: /my/distribution/id
phases:
post_build:
commands:
- aws cloudfront create-invalidation \
--distribution-id ${DISTRIBUTION_ID} \
--paths '/*'
- Name: InvalidateCache
Actions:
- Name: InvalidateCache
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: "1"
Configuration:
ProjectName: !Ref InvalidateCacheProject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment