Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cleaning Up Old Files in AWS CodePipeline

I have CodePipeline set up to build and deploy a static Vue site from my Github repo to an S3 bucket. But since the built files have hashed names (e.g. app.2c71f2bb.js), after each deploy, the old files still remain in the bucket. I'm wondering what's a common way of dealing with this issue? And how would I go about doing it?

like image 801
Axiaz Avatar asked Dec 26 '19 04:12

Axiaz


People also ask

What are some use cases for AWS CodePipeline?

Use Cases for CodePipeline. You can create pipelines that integrate with other AWS services. These can be AWS services, such as Amazon S3, or third-party products, such as GitHub. This section provides examples for using CodePipeline to automate your code releases using different product integrations.

How to delete files from AWS S3 bucket?

To delete the files in the S3 bucket, you can use the aws s3 rm --recursive command as you already alluded to. You can pass in the bucket name from the pipeline to CodeBuild by setting it in the environment variable.

How do I use CodePipeline with AWS Lambda?

Use CodePipeline with AWS Lambda for continuous delivery of Lambda-based and serverless applications When you create a pipeline, CodePipeline integrates with AWS products and services that act as action providers in each stage of your pipeline.

How do I remove EFS resources from an Amazon EC2 instance?

Remove Amazon EFS resources (file system, mount target). Terminate the EC2 instance you created for this walkthrough. You can also delete EC2 resources using the console. For instructions, see Terminating an Instance in the Amazon EC2 User Guide for Linux Instances. Delete the mount target.


1 Answers

Without knowing the stages in your pipeline I am going to assume that you have a CodeBuild step already defined because you mentioned a build.

Checkout > Build > Deploy (S3)

Remove the Deploy step and add this to CodeBuild,

            post_build:
              commands:
              - aws s3 sync ${LOCAL_FILES} s3://${S3_BUCKET_NAME} --delete

When doing this you will need to add the relevant permissions to your CodeBuild role, not the CodePipeline role.

like image 144
George Rushby Avatar answered Oct 11 '22 09:10

George Rushby