Get AWS Account ID from Boto

后端 未结 3 1771
悲哀的现实
悲哀的现实 2020-12-16 10:05

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 fi

3条回答
  •  执念已碎
    2020-12-16 10:34

    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"]
    

提交回复
热议问题