Skip to content

Instantly share code, notes, and snippets.

@dacamo76
Created December 7, 2012 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacamo76/4235890 to your computer and use it in GitHub Desktop.
Save dacamo76/4235890 to your computer and use it in GitHub Desktop.
Get keys recursively from S3
#!/usr/bin/env python
import boto
import os
import sys
bucket_name = str(sys.argv[1])
dirname = str(sys.argv[2])
def files(keys):
return (key for key in keys if not key.name.endswith('/'))
s3 = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = s3.get_bucket(bucket_name)
keys = bucket.list(dirname)
for key in files(keys):
path, file = os.path.split(key.name)
print('Downloading {0}'.format((key.name)))
if not os.path.exists(path):
os.makedirs(path)
key.get_contents_to_filename(key.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment