Skip to content

Instantly share code, notes, and snippets.

@Behoston
Created November 10, 2021 19:01
Show Gist options
  • Save Behoston/f69ffb9b345d58db077ad0fb19d04f0f to your computer and use it in GitHub Desktop.
Save Behoston/f69ffb9b345d58db077ad0fb19d04f0f to your computer and use it in GitHub Desktop.
AWS boto3 Assume Role (S3 example)
import boto3
from botocore.client import Config
sts_client = boto3.client('sts')
assumed_role_object = sts_client.assume_role(
RoleArn="arn:aws:iam::111111111111:role/Administrator",
RoleSessionName="testing-assume-role",
)
credentials = assumed_role_object['Credentials']
s3_resource = boto3.resource(
's3',
aws_access_key_id=credentials['AccessKeyId'],
aws_secret_access_key=credentials['SecretAccessKey'],
aws_session_token=credentials['SessionToken'],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment