[feature request] Delete non-empty bucket
See original GitHub issueWhen I try to delete a bucket, I get the following error message:
botocore.exceptions.ClientError: An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty
I know there are objects in the bucket. When I tell boto to delete a bucket, I expect the objects to be deleted too.
I understand there are circumstances where users might like this warning. So what I propose is an option for the client.delete_bucket()
function, like:
client.delete_bucket(Bucket='mybucketname',DeleteIfNonEmpty=True)
Where DeleteIfNonEmpty
is False by default.
Then if DeleteIfNonEmpty
is True, boto seamlessly deletes the whole bucket, just like deleting a directory in a file browser.
The alternative is for the user to
- manually list every object in the bucket;
- manually delete every object in the bucket; then
- actually delete the bucket
This is a lot of work for something which takes 2 clicks in the web console. Boto should handle this work for me.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
Yes, if you want to ultimately use the functionality in s3tranfser we recommend using the interface exposed through boto as those will remain stable, where as the underlying s3transfer interfaces may not. However, higher level s3 logic could theoretically be added there.
We try not to add too much high level logic on top of API calls as that creates feature disparity between this SDK and the ones for other languages. To be blunt, a proper implementation of it would be more complex than the snippet above and realistically I don’t see this feature being incorporated in at the SDK level. This truly is a request for the service team.
For reference, a quick way to delete all (non-versioned) objects in a bucket using resource models:
There is also a versioned objects collector that would allow you to do something similar for versioned objects, but do be careful as that may end up making a lot of requests.
Here’s the code I’ve written as a workaround. I propose that we just integrate this into boto. If someone can me point to the right location in the repo, I’ll make a pull request.