Search code examples
amazon-web-servicesamazon-s3aws-codepipelineaws-code-deploy

Move child folder content to an Amazon S3 bucket using AWS Code Deploy


I have created the below-mentioned pipeline in AWS.

CodeCommit -> CodeBuild -> CodeDeploy

I am using ng serve command to build the Angular JS source code and it creates a folder named dist and moves all the build content.

When deploying the build result to an Amazon S3 bucket, is it possible to move only the content inside the dist folder?

At the moment, all the source files are being transferred to the Amazon S3 bucket with the dist folder.

Other than writing a Lambda function to achieve this, is there a shortcut to achieve this within the pipeline?


Solution

  • I wonder why you have used CodeDeploy for S3 copying. You can achieve the same using CodeBuild itself.

    CodeCommit => CodePipeline => CodeBuild => S3
    

    After creating the build (dist), add commands for S3 sync in your buildspec.yml file

    Sample few lines of buildspec.yml for your use case.

    - ng serve
    - ls -ltr
    - cd dist
    - aws s3 sync . s3://YOUR_BUCKET --acl bucket-owner-full-control