How to delete all contents/objects of Amazon S3 bucket

12 / Nov / 2011 by Deepak Mittal 1 comments

If you have an S3 bucket with a huge number of files, and you want to delete the bucket, you need to empty the bucket first. If the bucket has a handful of files, then it is easy enough from the AWS interface, but if the bucket has a large number of files, then AWS interface is not an option; and you must use s3cmd or may be some other tool which allows this.

s3cmd is a command-line tool for manipulating S3 buckets and objects; and as you would expect, it does have a way to recursively delete all objects in a bucket.

s3cmd del –recursive –force <bucket_url>

What’s annoying is that S3 does not provide this capability natively. The above command probably simply lists all the objects first internally; and then makes a delete call on each object.

It took me a while to figure this out, because it does not seem to be documented, I found this in one of the comments on S3cmd page.



Tag -

s3 s3cmd

comments (1 “How to delete all contents/objects of Amazon S3 bucket”)

  1. S3 Browser

    If your bucket contains hundreds of thousands of files, you’d better to use multi-threaded approach. Deleting objects in one thread may take a weeks.

    If versioning enabled for the bucket, you will also need delete all versions before deleting the bucket.

    S3 Browser Freeware can effectively delete very large amounts of files using multiple threads. It also does support versioned buckets. So, if you have access to Windows machine, give it a try.


Leave a Reply

Your email address will not be published. Required fields are marked *