Skip to content

Instantly share code, notes, and snippets.

@jg75
Last active December 16, 2019 18:22
Show Gist options
  • Save jg75/ccd46ce99bf3123c2fc2cce61631c667 to your computer and use it in GitHub Desktop.
Save jg75/ccd46ce99bf3123c2fc2cce61631c667 to your computer and use it in GitHub Desktop.
Get the AWS account id for the current session user's credentials
import boto3
def get_account_id(session):
"""
Get Account Id.
Get the AWS account id for the current session user's credentials.
"""
client = session.client("sts")
access_key_id = session.get_credentials().access_key
response = client.get_access_key_info(AccessKeyId=access_key_id)
return response["Account"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment