3
votes

I used this command to delete all the files in it and delete the bucket itself. aws s3 rb s3://<bucket_name> --force

It did delete the files in the bucket but gave an error remove_bucket failed: s3://<bucket> 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.

The bucket is empty. Versioning was never enabled. But in the console, when clicked on "show" , I can see files that are marked 'delete'.

But, shouldn't the --force delete them as well. I need to write an aws cli command to delete all files in an s3 bucket and the bucket. The first command simply fails. But that is all the documentation states.

2

2 Answers

3
votes

If you run aws s3 rb help you will see the following:

--force (boolean) Deletes all objects in the bucket including the bucket itself. Note that versioned objects will not be deleted in this process which would cause the bucket deletion to fail because the bucket would not be empty. To delete versioned objects use the s3api delete-object command with the --version-id parameter.

0
votes

I figured out the issue. When I upload a new file, I have to set the availability for the file. Depending on the type of availability, the bucket may or may not get deleted. If you are doing it through CF templates, make sure you do not specify "versioning-configuration". By default, s3 is not created with versioning enabled, but if specified on the template as "suspended" cloud formation thinks the versioning was once enabled and is now suspended.