{{ !articles[0].partner.isSponsoringArticle ? "Platinum" : "Portal" }} Partner
architects,cloud,tips and tricks,s3,aws

Quick Look at the New S3 Multi-Object Delete Funcitonality

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.

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks