Over a million developers have joined DZone.
Platinum Partner

Quick Look at the New S3 Multi-Object Delete Funcitonality

· Cloud Zone

The Cloud Zone is brought to you in partnership with Mendix. Better understand the aPaaS landscape and how the right platform can accelerate your software delivery cadence and capacity with the Gartner 2015 Magic Quadrant for Enterprise Application Platform as a Service.

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-

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.

The Cloud Zone is brought to you in partnership with Mendix. Discover how Mendix for Mobile App Deveopment makes it incredibly fast and easy for any developer to build engaging multi-channel apps.


Published at DZone with permission of Jason Whaley , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}