Last active
February 28, 2019 17:58
-
-
Save ebarault/d576495e102750c8b02e597a4baa7202 to your computer and use it in GitHub Desktop.
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
import boto3 | |
from boto3.session import Session | |
role_arn = os.environ.get('ASSUME_ROLE') | |
if roleArn: | |
client = boto3.client('sts') | |
assumed_role = client.assume_role(RoleArn=roleArn, RoleSessionName='test') | |
session = Session(aws_access_key_id=assumed_role['Credentials']['AccessKeyId'], | |
aws_secret_access_key=assumed_role['Credentials']['SecretAccessKey'], | |
aws_session_token=assumed_role['Credentials']['SessionToken']) | |
s3_client = session.client('s3') | |
s3 = session.resource('s3') | |
else: | |
s3_client = boto3.client('s3') | |
s3 = boto3.resource('s3') | |
s3.Bucket('myBucket').download_file('myKey', 'myFileName') | |
s3_client.upload_file('myKey', 'myBucket', 'myFileName') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment