Skip to content

Instantly share code, notes, and snippets.

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