Convenient to get a connection from boto.connect_s3, a bucket from there, and even a key.
from cStringIO import StringI
from boto import connect_s3
# token
access_key = ''
secret_key = ''
# bucket, key
bucket_name = ''
file_key = ''
#Get files from S3
conn = connect_s3(access_key, secret_key)
bucket = conn.get_bucket(bucket_name)
key = bucket.get_key(file_key)
# key_Returns None if could not be retrieved by name
if not key:
return u'No'
#File download and write to StgingIO
fp = StringIO()
key.get_contents_to_file(fp)
fp.seek(0)
Recommended Posts