Draft
Add CloudFront invalidation to CodePipeline build stage#4
Conversation
Co-authored-by: ak4dev <92195328+ak4dev@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Review buildspec.yml for CloudFront invalidation on deployment
Add CloudFront invalidation to CodePipeline build stage
Mar 14, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The buildspec.yml had no post-deployment step, leaving CloudFront serving stale assets after each pipeline run.
Changes
buildspec.yml— newpost_buildphase with three guarded steps:aws s3 sync dist/ s3://$S3_BUCKET --delete— syncs built assets, removes stale filesaws cloudfront create-invalidationon$DISTRIBUTION_ID— primary distribution invalidation$EXTRA_DISTRIBUTION_IDS— handles multiple distributions (aligns with theDEV_DIST_ID/IO_DIST_IDpattern already inpackage.json)All steps are no-ops when their env var is unset — PR/local builds are unaffected.
Required CodeBuild configuration
S3_BUCKETDISTRIBUTION_IDEXTRA_DISTRIBUTION_IDSThe CodeBuild IAM role also needs
s3:PutObject/s3:DeleteObject/s3:ListBucketon the bucket andcloudfront:CreateInvalidationon the distributions.Original prompt
Created from VS Code.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.