Skip to content

Instantly share code, notes, and snippets.

@stewmi
Created December 16, 2019 17:08
Show Gist options
  • Save stewmi/e36ca8a6e7cb1d5fe1962c745c5fdc9d to your computer and use it in GitHub Desktop.
Save stewmi/e36ca8a6e7cb1d5fe1962c745c5fdc9d to your computer and use it in GitHub Desktop.
response = sts.assume_role(
RoleArn=ORGS_ROLE,
RoleSessionName="OrgsListRole"
)
session = boto3.Session(
aws_access_key_id=response['Credentials']['AccessKeyId'],
aws_secret_access_key=response['Credentials']['SecretAccessKey'],
aws_session_token=response['Credentials']['SessionToken']
)
organizations = session.client('organizations', region_name="us-east-1")
account_ids = list()
# try:
response = organizations.list_accounts()
for account in response['Accounts']:
account_ids.append(account['Id'])
return account_ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment