Skip to content

Instantly share code, notes, and snippets.

@garnaat
Created February 27, 2012 17:14
Show Gist options
  • Save garnaat/1925584 to your computer and use it in GitHub Desktop.
Save garnaat/1925584 to your computer and use it in GitHub Desktop.
Dowload all of the keys in an S3 bucket with boto
import boto
import os
def download_keys(bucket_name, dst_dir):
"""
Very simple example showing how to download all keys in a bucket.
Assumes key names don't include path separators. Also assumes that
you don't have zillions of objects in the bucket. If you have a lot
you would want to get several download operations going in parallel.
"""
s3 = boto.connect_s3()
bucket = s3.lookup(bucket_name)
for key in bucket:
path = os.path.join(dst_dir, key.name)
key.get_contents_to_filename(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment