michaelconnor00
12/22/2015 - 11:35 PM

Boto3 S3 upload and Download

Boto3 S3 upload and Download

# If bucket is private
AWS_ACCESS_KEY = 'your access key'
AWS_SECRET_KEY = 'your secret key'
AWS_REGION = 'your region'

session = boto3.session.Session(
  aws_access_key_id=AWS_ACCESS_KEY,
  aws_secret_access_key=AWS_SECRET_KEY,
  region_name=AWS_REGION
)
s3_client = session.client('s3')

# If the bucket is public
s3_client = boto3.client('s3')
open('hello.txt').write('Hello, world!')

# Once the client is created.

# Upload the file to S3
s3_client.upload_file('hello.txt', 'MyBucket', 'hello-remote.txt')

# Download the file from S3
s3_client.download_file('MyBucket', 'hello-remote.txt', 'hello2.txt')
print(open('hello2.txt').read())