Skip to content

Instantly share code, notes, and snippets.

@drAlberT
Forked from gene1wood/role_arn_to_session.py
Created January 24, 2018 17:53
Show Gist options
  • Save drAlberT/61c04a63249a0273c206bc464a2a0e7a to your computer and use it in GitHub Desktop.
Save drAlberT/61c04a63249a0273c206bc464a2a0e7a to your computer and use it in GitHub Desktop.

Revisions

  1. @gene1wood gene1wood created this gist Dec 29, 2016.
    16 changes: 16 additions & 0 deletions role_arn_to_session.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    import boto3

    def role_arn_to_session(**args):
    """
    Usage :
    session = role_arn_to_session(
    RoleArn='arn:aws:iam::012345678901:role/example-role',
    RoleSessionName='ExampleSessionName')
    client = session.client('sqs')
    """
    client = boto3.client('sts')
    response = client.assume_role(**args)
    return boto3.Session(
    aws_access_key_id=response['Credentials']['AccessKeyId'],
    aws_secret_access_key=response['Credentials']['SecretAccessKey'],
    aws_session_token=response['Credentials']['SessionToken'])