[root@sgd ~]# aws --version aws-cli/1.2.13 Python/3.3.3 Linux/3.8.4-1-ARCH [root@sgd ~]# aws s3 rb --recursive s3://resumetest Unknown options: --recursive [root@sgd ~]# aws s3 rb s3://resumetest --recursive Unknown options: --recursive [root@sgd ~]# aws s3 rb s3://resumetest remove_bucket failed: s3://resumetest/ A client error (BucketNotEmpty) occurred when calling the DeleteBucket operation: The bucket you tried to delete is not empty
What am I missing?
How do I remove a bucket in one step?
You can use the --force
option:
--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
Most helpful comment
+1 for this - this is painful