Can you get the AWS account name from boto?
3 answers
To get your AWS account alias in boto3
:
alias = boto3.client('iam').list_account_aliases()['AccountAliases'][0]
- While the API response allows for multiple account aliases, the AWS docs say there can only be one per account.
- the account alias is not the same as the account name , but it is alphanumeric and more usable than the account number.
- Obtaining an alias also does not require access privileges like getting an account name through the boto3 service
organizations
.
To get your account ID (account number):
id = boto3.client('sts').get_caller_identity().get('Account')
+7
source to share
from Get AWS Account ID from Boto
id = boto3.client('sts').get_caller_identity().get('Account')
then
name = boto3.client('organizations').describe_account(AccountId=id).get('Account').get('Name')
+4
source to share