Created
November 13, 2011 18:17
-
-
Save garrettr/1362441 to your computer and use it in GitHub Desktop.
S3 Upload w/ Boto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upload_to_s3(local_file, bucket_name, key_name=None, acl='private'): | |
''' | |
Uploads local_file to bucket_name on Amazon S3 | |
key_name is the "filename" on Amazon S3. We'll default to the local file's name if | |
no alternative key_name is specified. | |
''' | |
# connect to Amazon S3 | |
conn = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
bucket = conn.create_bucket(bucket_name) | |
k = Key(bucket) | |
if key_name: | |
k.key = key_name | |
else: | |
k.key = local_file.split("/")[-1] | |
# encrypt_key=True for AES-256 encryption while at rest on Amazon's servers | |
k.set_contents_from_filename(local_file, encrypt_key=True) | |
k.set_acl(acl) | |
debug("Uploaded %s to S3" % local_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment