AWS CodeBuild: buildspec.yml To Push Files to S3

3/18/2020 9:41:47 PM

Create an AWS buildspec file for CodePipeline and CodeBuild to push CodeCommit changes to S3. After push, invalidate a CloudFront distribution. Place the buildspec.yml file in the root of your git repository.

buildspec.yml


version: 0.2
phases:
 install:
   commands:
     - echo "install step"         	     
 pre_build:
   commands:
     - echo "pre_build step"
 build:
   commands:
     - echo "build step"     
     - pwd                    
     - aws s3 sync "./Folder_With_Files_To_Copy" "s3://mybucketname/optional_sub_directory/"
     - aws cloudfront create-invalidation --distribution-id "CLOUDFRONT_ID" --paths '/*'
 post_build:
   commands:
     - echo "post_build step"