Cloud Zone is brought to you in partnership with:

Jason Whaley is a Java developer specializing in service oriented architectures, enterprise integration, cloud computing, and continuous integration. Previously, Jason has worked in multiple roles for both public companies as well as government institutions in a variety of roles for several broad ranging Java based projects. Presently, Jason works at Nodeable as a platform developer where he is helping build a next generation infrastructure monitoring and analytics tool. He is also a contributor to The Basement Coders Podcast. Jason is a DZone MVB and is not an employee of DZone and has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

Quick Look at the New S3 Multi-Object Delete Funcitonality

04.27.2012
| 3505 views |
  • submit to reddit

I’m a little late posting about this one, but it is still a cool feature

AWS just keeps pumping out features. One of the latest was multi object delete in s3.

Previously, if you wanted to delete multiple objects within an s3 bucket, each delete operation had to be contained in a single API requests… which quite honestly is slow and clunky. If you wanted to delete 5,000 objects you are going to have to make 5,000 API calls.

This is no more with the addition of multi-object delete. This feature was pretty quickly incorporated in to boot as well. Here is how simple it is. Let’s say I wanted to delete all objects that ended in “6” within a given bucket. I can now just pass the result of a list comprehension to the Bucket delete_keys method in a very concise and pythonic manner.

>>> import boto
>>> s3 = boto.connect_s3()
>>> bucket = s3.get_bucket("basementcoders.logging")
>>> result = bucket.delete_keys([key.name for key in bucket if key.name[-1] == '6'])
>>> result.deleted
[<Deleted: basementcoders.downloads2011-01-30-21-37-29-09929716CC5526B6>, <Deleted: basementcoders.downloads2011-01-16-17-19-55-
E50B56C60B99F316>]

The result reference I get back and report the keys that were actually deleted and what keys resulted in errors. All of this happens with a single API request.

Published at DZone with permission of Jason Whaley, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)