Created
February 25, 2020 06:07
-
-
Save vidit0210/15e37b273662bfeedfe61e7bdddf3135 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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