Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Boto3 with IAM roles
#!/usr/bin/env python3
import boto3
sts = bot3.client('sts')
role = sts.assume_role(
RoleArn="arn:aws:iam::ACCOUNT NUMBER:role/ROLENAME",
RoleSessionName="AssumeRoleSession1"
)
credentials = assumed_role_object['Credentials']
s3 = boto3.resource(
's3',
aws_access_key_id=credentials['AccessKeyId'],
aws_secret_access_key=credentials['SecretAccessKey'],
aws_session_token=credentials['SessionToken'],
)
for bucket in s3_resource.buckets.all():
print(bucket.name)
# use S3 appropriately from here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment