Skip to content

Instantly share code, notes, and snippets.

@vidit0210
Created February 25, 2020 06:07
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 vidit0210/15e37b273662bfeedfe61e7bdddf3135 to your computer and use it in GitHub Desktop.
Save vidit0210/15e37b273662bfeedfe61e7bdddf3135 to your computer and use it in GitHub Desktop.
# Write and Reading from S3 is just as easy
# files are referred as objects in S3.
# file name is referred as key name in S3
# Files stored in S3 are automatically replicated across 3 different availability zones
# in the region where the bucket was created.
# http://boto3.readthedocs.io/en/latest/guide/s3.html
def write_to_s3(filename, bucket, key):
with open(filename,'rb') as f: # Read in binary mode
return boto3.Session().resource('s3').Bucket(bucket).Object(key).upload_fileobj(f)
def download_from_s3(filename, bucket, key):
with open(filename,'wb') as f:
return boto3.Session().resource('s3').Bucket(bucket).Object(key).download_fileobj(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment