Closed kaihendry closed 10 years ago
You can use the --force
option:
OPTIONS
--force Deletes all objects in the bucket including the bucket itself.
Although, we can improve the error message in this case to hint to the user what to do if the bucket is not empty.
I don't see this force option documented. aws s3 help rb | grep force
The format for help is aws s3 rb help
$ PAGER=cat aws s3 rb help
RB() RB()
NAME
rb -
DESCRIPTION
Deletes an S3 bucket.
SYNOPSIS
rb <S3Path>
[--force]
OPTIONS
--force Deletes all objects in the bucket including the bucket itself.
EXAMPLES
1) The following rb command removes a bucket. In this example, the
user's bucket is mybucket. Note that the bucket must be empty in order
to remove.
aws s3 rb s3://mybucket
Output:
remove_bucket: mybucket
2) The following rb command uses the --force parameter to first remove
all of the objects in the bucket and then remove the bucket itself. In
this example, the user's bucket is mybucket and the objects in mybucket
are test1.txt and test2.txt.
aws s3 rb s3://mybucket --force
Output:
delete: s3://mybucket/test1.txt
delete: s3://mybucket/test2.txt
remove_bucket: mybucket
Wow aws s3 rb help
is counter-intuitive if you work with ubiquitous tools like git. First I've seen of this type. getopts interfaces further broken.
remove_bucket failed: s3://
How to remove the versions quickly
+1 for this - this is painful
:+1: Sept 2017?
August 2018
I am also running into this problem for a versioned bucket. There are some longer scripts people seemed to have posted for this as a resolution (either with boto or cli):
These solutions seem very verbose for something that should be pretty simple and in the CLI
The --force
option still does not work for versioned buckets
Can we re-open this ticket?
Maybe this behavior is intentional? If you have a versioned bucket, it’s often because you really really don’t want to lose the contents forever. So perhaps deleting it should be quite hard. A force override with a prompt seems like a good idea though.
please re-open still an issue
There is overlap here with this open issue being tracked: https://github.com/aws/aws-cli/issues/4070
There are workarounds for removing a bucket with versioning enabled discussed here: https://stackoverflow.com/questions/29809105/how-do-i-delete-a-versioned-bucket-in-aws-s3-using-the-cli
What am I missing?
How do I remove a bucket in one step?