in resources/AccountCreationLambda.py [0:0]
def assume_role(account_id, account_role):
sts_client = boto3.client('sts')
role_arn = 'arn:aws:iam::' + account_id + ':role/' + account_role
assuming_role = True
while assuming_role is True:
try:
assuming_role = False
assumedRoleObject = sts_client.assume_role(
RoleArn=role_arn,
RoleSessionName="NewAccountRole"
)
except botocore.exceptions.ClientError as e:
assuming_role = True
print(e)
print("Retrying...")
time.sleep(10)
# From the response that contains the assumed role, get the temporary
# credentials that can be used to make subsequent API calls
return assumedRoleObject['Credentials']