Skip to content

Instantly share code, notes, and snippets.

@nickfox-taterli
Created January 10, 2020 05:57
Show Gist options
  • Save nickfox-taterli/e82fc19ae8951f755bd4768bacf124e1 to your computer and use it in GitHub Desktop.
Save nickfox-taterli/e82fc19ae8951f755bd4768bacf124e1 to your computer and use it in GitHub Desktop.
AWS Cross Account Python Script
import boto3
client = boto3.client('sts',region_name='us-east-1',aws_access_key_id='xxxx',aws_secret_access_key='xxxx')
response = client.assume_role(
RoleArn = 'arn:aws:iam::066600000000:role/xxx',
RoleSessionName = 'newsession',
DurationSeconds = 43200
)['Credentials']
credentials = '''
[default]
aws_access_key_id=%s
aws_secret_access_key=%s
aws_session_token=%s
''' % ( response['AccessKeyId'] , response['SecretAccessKey'] , response['SessionToken'] )
fo = open("/root/.aws/credentials", "w")
fo.write(credentials)
fo.close()
print(credentials)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment