Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Quick Look at the New S3 Multi-Object Delete Funcitonality

DZone's Guide to

Quick Look at the New S3 Multi-Object Delete Funcitonality

· Cloud Zone ·
Free Resource

Discover a centralized approach to monitor your virtual infrastructure, on-premise IT environment, and cloud infrastructure – all on a single platform.

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.

Learn how to auto-discover your containers and monitor their performance, capture Docker host and container metrics to allocate host resources, and provision containers.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}