Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Delete Empty S3 Bucket

I have an S3 bucket that is 100% empty. Versioning was never enabled on the bucket. However, I still cannot remove the bucket. I have tried via the Console and the CLI tool. On the console it just says "Error" with no error message. From the cli and api it tells me: "An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty". I have tried all of the following:

aws s3 rb s3://<bucket_name> --force -> BucketNotEmpty

aws s3 rm s3://<bucket_name> --recursive -> No output (because it's already empty)

aws s3api list-object-versions --bucket <bucket_name> -> No output (because versioning was never enabled)

aws s3api list-multipart-uploads --bucket <bucket_name> -> No outputs

aws s3api list-objects --delimiter=/ --prefix= --bucket <bucket_name> -> No Output (because it's empty)

  • It has no dependencies (it's not used by cloudfront or anything else that I'm aware of).
  • The bucket has been empty for approximately 5 days.
  • I was able to delete another very similar bucket with the same IAM user. Additionally my IAM user has Admin access.
like image 398
Tim Martin Avatar asked Jan 23 '17 17:01

Tim Martin


People also ask

How do I force delete a S3 bucket?

To delete an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, select the option next to the name of the bucket that you want to delete, and then choose Delete at the top of the page.

Can I force CloudFormation to delete non empty S3 bucket?

1 Answer. You can try creating a lambda function that wipes up your bucket. You'll have to invoke your lambda function from CloudFormation.

Do empty S3 Buckets cost money?

Empty S3 buckets don't cost anything. You are only charged by the size of the objects in the bucket, the storage class and the access.


2 Answers

I was facing this same problem. I was able to fix the issue by going into the bucket and deleting the "Bucket Policy" for the bucket. After that, deleting the bucket worked correctly.

I did this through the AWS console, for an S3 bucket created by Elastic Beanstalk (ie elasticbeanstalk-us-west-2-861587641234). I imagine the creation script includes a policy to prevent people from accidentally deleting the bucket.

like image 140
Federico Avatar answered Sep 30 '22 04:09

Federico


I had a similar issue and was able to delete the bucket after waiting overnight. It's a pretty weak solution but may save you and other some time from pounding on it.

If it's still not deleting after all the actions in the comments there are some things that only AWS support can fix properly. Again a weak answer but register a ticket with AWS support and then post their response here as an answer for others.

like image 27
Eric Nord Avatar answered Sep 30 '22 06:09

Eric Nord