amazon-web-servicesamazon-s3aws-codepipelineaws-codebuildbuildspec

How to add files from S3 bucket to output artifacts in AWS CodePipeline? (NodeJS)


I am using a AWS CodePipeline which fetches the source from my git repository, uses CodeBuild buildSpec to build and save output artifacts to S3 bucket, which ultimately gets deployed to Elastic BeanStalk (NodeJS Environment).

Everything works fine but I require the pipeline to copy 1 particular file from one of my AWS S3 buckets and add it to the output artifacts before deploying it to the EB

Can it be done using the buildSpec?

artifacts:
  files:
    - '**/*'
    # - How to add a file from S3 to the artifacts?

Solution

  • My recommendation is as part of the build or post_build, copy the required file from s3 into your build directory.

    build:
      commands:
        - echo "Build commands"
        - aws s3 cp --region=xx-xxxx-x "s3://file/in/s3" "local-file-instance-to-include"
    

    Then you will have the file copied from s3, available for your build, and you can add it to the artifacts output.