serverless: 'sls remove' fails when S3 bucket contains objects
For a given Serverless service where an S3 bucket has been created via the CloudFormation stack and some objects have been put in said bucket, running sls remove fails to succeed because the buckets will not delete unless empty.
I believe the same process used to empty the deployment buckets should also be applied to any buckets created through CloudFormation.
What I’m not sure of is whether this should be implemented in core or relegated to a plugin.
- Serverless Framework Version you’re using: 1.17
Proposed solution (added later by maintainers)
- Introduce
provider.shouldEmptyBucketsOnRemoveconfig option, and--empty-s3-bucketsCLI param. If it’s on, removal process prior removing stack on CloudFormation should first find all S3 buckets (aside of deployment one) in a stack to be removed (we should rely on template downloaded from AWS, and not one generated by Framework), and empty them. - If none of the above is not set, and removal fails with bucket not empty error, then present meaningful error message suggesting above options
⚠️ ⚠️ ⚠️ If you’d like to address that, but you’re not sure how to tackle this, please ask for help, we’ll provide a specific implementation spec you can follow!
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 16
- Comments: 18 (11 by maintainers)
--forceoption would be nice! +1Thanks for opening @ryanmurakami and thanks @horike37 for jumping in 👍
We’ve discussed a related feature in https://github.com/serverless/serverless/issues/3679 and https://github.com/serverless/serverless/issues/1609.
IMHO Serverless shouldn’t auto-remove something for you since the bucket can contain some important data (same for DynamoDB and other services). However the
--forceoption could be smth. we can add so that the user has to explicitly state that he wants to remove everything.I agree it’ll be good to have it in core.
I believe right approach, will be to internally remove the CloudFormation stack with instruction to ignore eventual error on bucket removal (I see that’s possible on console level, hence I assume we can do same via SDK). Then after stack is removed successfully, remove the bucket manually if it still exists.
Any thoughts on that?
@ryanmurakami Someone has released the feature as a plugin. This would be some of help to you. https://github.com/sinofseven/serverless-s3-remover
What case? manually put? IMO, if the objects have been put munually, should not implemente in core. However, if those have been put via
sls deployorsls deploy function, should implemente in core.@chenrui333 simply use serverless-s3-remover.