Created
April 8, 2023 23:31
-
-
Save subudear/e45b13ab3c33479babb0596524a0c9be to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import json | |
ACCOUNT_ID = "7088" | |
sts_client = boto3.client('sts',region_name="ap-southeast-2") | |
assumed_role_object =sts_client.assume_role(RoleArn="arn:aws:iam::7068:role/role_to_Access_s3",RoleSessionName="S3access") | |
print("assumed role: ", json.dumps(assumed_role_object,indent=4,default=str)) | |
creds = assumed_role_object["Credentials"] | |
print("creds: ", json.dumps(creds,indent=4,default=str)) | |
s3client = boto3.client("s3",aws_access_key_id=creds["AccessKeyId"],aws_secret_access_key=creds["SecretAccessKey"],aws_session_token=creds["SessionToken"],region_name="ap-southeast-2") | |
result = s3client.list_buckets() | |
print("buckets: ", json.dumps(result,indent=4,default=str)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment