I am using the below command to deploy lambda. It always create a new folder(.template and 1 more) in s3 bucket when there is change in my lamda project files. I want to overwrite the folder, so at any point in time, I will be having only 1 folder. How to do that?
sam deploy --no-fail-on-empty-changeset --s3-bucket bucketName --capabilities CAPABILITY_IAM --stack-name stackName --parameter-overrides "ParameterKey=Stage,ParameterValue=staging"
The easiest way to keep deployment artefact buckets "tidy" is to add a Bucket Lifecycle Rule that expires (deletes) objects after an arbitrary number of days.
You can create the rule in the S3 Console (Management > Lifecyle rules
). You can safely expire all the objects, including the "current" version. Artefacts are read only at deploy-time and will be re-created with the next sam deploy
.