3

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 Answers 2

3

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.

3
  • When versioning was never enabled, why does the s3 keep older versions of my files?
    – user10492117
    Oct 30, 2018 at 7:24
  • Well, the most likely reason is that versioning was once enabled on the bucket but was subsequently suspended.
    – jarmod
    Oct 30, 2018 at 8:38
  • 1
    It could also be abandoned multipart uploads... aws s3api list-multipart-uploads Oct 30, 2018 at 12:18
0

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.

1
  • Your comments about file availability are misleading. The only thing relevant here is that you created an S3 bucket and when you did that you supplied a versioning configuration. That (optional) versioning configuration was configured for 'Suspended' rather than 'Enabled'. After enabling Suspended versioning, S3 automatically adds a null version ID to every subsequent object stored thereafter in the bucket. Those null version IDs remained and that is the reason that you were unable to delete the bucket, even though the bucket appeared to be empty.
    – jarmod
    Oct 31, 2018 at 15:58

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.