aws / aws-cli

Universal Command Line Interface for Amazon Web Services
Other
15.52k stars 4.12k forks source link

Unable to remove bucket in one step #651

Closed kaihendry closed 10 years ago

kaihendry commented 10 years ago
[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?

jamesls commented 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.

kaihendry commented 10 years ago

I don't see this force option documented. aws s3 help rb | grep force

jamesls commented 10 years ago

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
kaihendry commented 10 years ago

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.

sureshamk commented 8 years ago

remove_bucket failed: s3:/// An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty. You must delete all versions in the bucket.

How to remove the versions quickly

voycey commented 7 years ago

+1 for this - this is painful

lmayorga1980 commented 7 years ago

:+1: Sept 2017?

alexkravets commented 6 years ago

August 2018

madhuravius commented 6 years ago

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):

  1. https://stackoverflow.com/questions/29809105/how-do-i-delete-a-versioned-bucket-in-aws-s3-using-the-cli 1b. (Same answer as #1 in comments): https://forums.aws.amazon.com/thread.jspa?threadID=167616
  2. Gist with cli that does something similar: https://gist.github.com/weavenet/f40b09847ac17dd99d16

These solutions seem very verbose for something that should be pretty simple and in the CLI

benhannel commented 3 years ago

The --force option still does not work for versioned buckets

deimosfr commented 3 years ago

Can we re-open this ticket?

benhannel commented 3 years ago

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.

chadReimers commented 2 years ago

please re-open still an issue

tim-finnigan commented 2 years ago

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