I have an AWS key and secret key and would like to call boto
to get the account name.
I can get account ID, but the AWS account name is a mystery.
I have an AWS key and secret key and would like to call boto
to get the account name.
I can get account ID, but the AWS account name is a mystery.
To get the AWS account alias in boto3
:
alias = boto3.client('iam').list_account_aliases()['AccountAliases'][0]
organizations
service.To get account ID (account number):
id = boto3.client('sts').get_caller_identity().get('Account')
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')
Its late but might be helpful for future. If you are using organization service then using below code you can fetch Account Name.
org = boto3.client('organizations')
account_name = org.describe_account(AccountId='account-id').get('Account')
print(account_name ['Name'])
It is only possible if you're using IAM and you want to retrieve that alias. If you have root credentials, it's not possible to retrieve the account name.
The related call is: get_account_alias()