0

AWS Codepipeline supports deploying to S3.

I have an Angular SPA that I'm deploying to S3 as a static website (using Cloudfront, etc)

When I do the ng build --prod command, I include outputHashing, which will change the file names deployed over time.

However when deploying to S3 in my Codepipeline, it's not removing old js/css files with different hashes, but continually adding new files

I'd like to use Codepipeline to deploy to S3 with the same behavior as

aws s3 sync ./dist s3://mywebsite-bucket.com/ --acl public-read --delete

Note the --delete flag.

Is this possible to set up in Codepipeline when deploying to S3?

maafk
  • 6,176
  • 5
  • 35
  • 58
  • Does this answer your question? [How to delete files in S3 using CodePipeline](https://stackoverflow.com/questions/57188543/how-to-delete-files-in-s3-using-codepipeline) – Munim Munna Mar 12 '23 at 17:09

1 Answers1

2

I use a similar set-up, as s3 deployment with --delete is currently not possible. Instead, see bash commands below, use a codebuild stage for deployment in the codepipeline.

echo "Syncing directory files to s3"
aws s3 sync ./dist s3://mywebsite-bucket.com/ \
--grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers \
--delete

Note, grants command will achieve same outcome as --acl public-read.

pkarfs
  • 993
  • 7
  • 19
  • I understand this, the question was how to get this effect in codepipeline when S3 is the [deployment provider](https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-s3deploy.html). It it's _not_ possible, I'll definitely revert to using codebuild in the way you show in the answer – maafk Apr 17 '20 at 09:20
  • Ah apologies i missed the bit where you only wanted to use s3 as your deployment option. Correct, this is not possible as the deployment uses essentially a cp instead of sync --delete. With no current additional configurations allowed to delete. But what is the structure of your pipeline? As to achieve what your after you'll need to do a build prior to deploying if your going to execute the cli commands. --updated answer to reflect – pkarfs Apr 17 '20 at 09:46