I have an AWS_ACCESS_KEY_ID and an AWS_SECRET_KEY. These are active credentials, so they belong to an active user, who belongs to an AWS Account. How, using Boto3, do I find the ID of this AWS Account?
To find your AWS account ID when signed in as the root userIn the navigation bar on the upper right, choose your account name or number and then choose My Security Credentials. Expand the Account identifiers section. The account number appears next to the label AWS account ID.
Finding Your Account ID using the AWS CLI Use the following command to view your user ID, account ID, and your user ARN: aws sts get-caller-identity.
The alias must be created under IAM settings for account (or using AWS CLI) - not all accounts will have an alias. Getting the alias doesn't require as much privilege to access as getting the account name via the boto3 organizations service.
The AccountID can be grabbed from the get-caller-identity sts function. This returns an "Account" field:
client = boto3.client("sts", aws_access_key_id=access_key, aws_secret_access_key=secret_key) account_id = client.get_caller_identity()["Account"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With