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')
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'])
For more info
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