Skip to content

Instantly share code, notes, and snippets.

@michaelconnor00
Created December 22, 2015 23:35
Show Gist options
  • Save michaelconnor00/3697e4cca333e5da17d6 to your computer and use it in GitHub Desktop.
Save michaelconnor00/3697e4cca333e5da17d6 to your computer and use it in GitHub Desktop.
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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment