Skip to content

Instantly share code, notes, and snippets.

@kylegalbraith
Last active April 27, 2023 12:20
Show Gist options
  • Save kylegalbraith/8aff085266b04f87dc738c8763e67bd2 to your computer and use it in GitHub Desktop.
Save kylegalbraith/8aff085266b04f87dc738c8763e67bd2 to your computer and use it in GitHub Desktop.
buildspec.yml with CloudFront invalidation
version: 0.2
phases:
install:
commands:
- echo "install step"
pre_build:
commands:
- echo "pre_build step"
build:
commands:
- aws s3 sync --delete . "s3://<your-static-website-bucket>"
post_build:
commands:
- aws cloudfront create-invalidation --distribution-id <your-distribution-id> --paths '/*'
@olen2006
Copy link

olen2006 commented Apr 1, 2021

Nice workaround.
Is there another way to achieve this? I know that post command will run even if the build fails ?

@liesislukas
Copy link

each phase has option to abort or continue on failure

on-failure: ABORT | CONTINUE

https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html

p.s. in this file aws s3 sync is used, you can actually use code build artifacts to upload to s3

@nyambeni
Copy link

nyambeni commented Dec 6, 2021

Hi Guys, Can this be done in a cross-account ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment