Created
February 8, 2019 02:01
-
-
Save Karunamon/16b0ec04f6131b4ac8395745a60f7ae3 to your computer and use it in GitHub Desktop.
Boto3 with IAM roles
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
#!/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