Skip to content

Instantly share code, notes, and snippets.

@takakabe
Created September 11, 2019 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takakabe/d39481b7a0d5e5d3fe2d234878f5b26b to your computer and use it in GitHub Desktop.
Save takakabe/d39481b7a0d5e5d3fe2d234878f5b26b to your computer and use it in GitHub Desktop.
Python
import boto3
sts = boto3.client('sts')
iam_role_arn = 'arn:aws:iam::123456789012:role/wawawa_role'
response = sts.assume_role(
RoleArn=iam_role_arn,
RoleSessionName='wawawa'
)
session = boto3.Session(
aws_access_key_id=response['Credentials']['AccessKeyId'],
aws_secret_access_key=response['Credentials']['SecretAccessKey'],
aws_session_token=response['Credentials']['SessionToken'],
region_name='ap-northeast-1'
)
role_sts = session.client('sts')
print(role_sts.get_caller_identity())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment