Last active
December 16, 2019 18:22
-
-
Save jg75/ccd46ce99bf3123c2fc2cce61631c667 to your computer and use it in GitHub Desktop.
Get the AWS account id for the current session user's credentials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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