Can you get the AWS account name from boto?

I have AWS key and private key and I would like to call boto

to get the account name.

I can get the account ID, but the AWS account name is a mystery.

+7


source to share


3 answers


To get your AWS account alias in boto3

:

alias = boto3.client('iam').list_account_aliases()['AccountAliases'][0]

      



To get your account ID (account number):

id = boto3.client('sts').get_caller_identity().get('Account')

      

+7


source


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


This is only possible if you are using IAM and want to get this alias. If you have root credentials, it is not possible to get the account name.

Associated call: get_account_alias()

http://boto.readthedocs.org/en/latest/ref/iam.html#boto.iam.connection.IAMConnection.get_account_alias

+2


source







All Articles