Reputation: 117
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?
Upvotes: 6
Views: 3391
Reputation: 187
Upvotes: 0
Reputation: 1355
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.
Upvotes: 11
Reputation: 8890
Throw in a CodeBuild action in CodePipeline to run some custom aws cli commands to remove the S3 objects. Make sure your CodeBuild service role has permissions to do the relevant AWS API actions.
Upvotes: 0