Skip to content

Instantly share code, notes, and snippets.

@gmariette
Created February 25, 2020 15:45
Show Gist options
  • Select an option

  • Save gmariette/4ff8165dbc8a91841c4a467a2fbed5a9 to your computer and use it in GitHub Desktop.

Select an option

Save gmariette/4ff8165dbc8a91841c4a467a2fbed5a9 to your computer and use it in GitHub Desktop.
import boto3
awsAccounts = {
"Account N1": { "id": "123456789", "role": "iam-role", "region": "eu-west-3", "envs": ["env01", "env02", "env03"] },
}
stsClient = boto3.client('sts')
for awsAccount in awsAccounts:
assumedRoleObject=stsClient.assume_role(
RoleArn="arn:aws:iam::"+awsAccounts[awsAccount]["id"]+":role/"+awsAccounts[awsAccount]["role"],
RoleSessionName="StatusPageSession"
)
credentials=assumedRoleObject['Credentials']
ACCESS_KEY=credentials.get("AccessKeyId")
SECRET_KEY=credentials.get("SecretAccessKey")
SESSION_TOKEN=credentials.get("SessionToken")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment