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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With