AWS CodeDeploy and CodePipeline Using S3 bucket content as Source

143 Views Asked by At

I am using AWS CodePipeline to deploy to an EC2 instance whenever there's a file change in my S3 bucket. Currently the Code Pipeline automatically kicks off a deployment only when I make a change to a file inside of a specific zip folder inside the S3 bucket (SampleApp_Linux.zip).

enter image description hereThis is inconvenient when using AWS CDK, because I have to unzip the object, make changes to my file, and then zip it again before pushing changes. I also can't see my files in the zipped folder from a code repo.

I'm wondering is there a way to have CodePipeline automatically start deployments whenever there's a change to any file in the S3 bucket and not just those inside of the zip folder (ie changes to myDummyFiles folder)?

Update: I am creating all of these resources via AWS CDK and using the bucketDeployment resource to push my S3 file changes in SampleApp_Linux folder to CDK. If it isn't possible for Pipelines to track unzipped changes to S3 perhaps AWS CDK can zip the SampleApp_Linux folder for me before it deploys it to AWS. That way CodePipeline will pick up the change.

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.BucketDeployment.html

Attached are screenshots of my CodePipeline SourceAction and S3 bucket.

enter image description here

1

There are 1 best solutions below

4
fedonev On

Here's one option: Configure your pipeline source to run on changes to your code repo. Next, add a BucketDeployment construct to the pipeline. On each pipeline run, the BucketDeployment bundles your SampleApp_Linux code and saves it to a S3 bucket.

The BucketDeployment construct automagically (using a Custom Resource) will create your code artefact from the source path and copy it to a destinationBucket. The extract: false setting tells the CDK not to unzip the artefact at the S3 destination.

new BucketDeployment(this, "LinuxAppDeployment", {
    sources: [Source.asset(path.join(__dirname, "./path/to/SampleApp_Linux"))],
    destinationBucket: bucket,
    extract: false,
});