从Boto获取AWS账户ID [英] Get AWS Account ID from Boto

查看:146
本文介绍了从Boto获取AWS账户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AWS_ACCESS_KEY_ID和一个AWS_SECRET_KEY.这些是活动凭证,因此它们属于一个活动用户,该用户属于一个AWS账户.如何使用Boto3查找该AWS账户的ID?

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 find the ID of this AWS Account?

推荐答案

可以从get-caller-identity sts函数获取AccountID.这将返回帐户"字段:

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

这篇关于从Boto获取AWS账户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆