[英]Work with RDS Tags in boto3 / How to get ARN in boto3
我想知道如何获得帐号
不幸的是,这并不容易找到。 但是你可以有一些技巧:
如果您有权访问某些 API 调用,则可以获取安全组或 AMI 并检查 OwnerId。
>>> import boto3
>>> client = boto3.client('ec2')
>>> client.describe_security_groups()['SecurityGroups'][0]['OwnerId']
'1234567890'
只有当您可以保证 SG 或 AMI 是由您要查找的帐户创建时,此技巧才有效。
使用对 IAM 的 API 调用并解析您自己的角色或用户的 ARN
>>> client = boto3.client('iam')
>>> client.get_user()['User']['Arn'].split(':')[4]
将您的 boto3 升级到最新版本,它现在返回一个新属性DBInstanceArn
http://boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.describe_db_instances
使用 boto3,您可以使用此代码获取 db arn....
from boto3 import client
REGION = "us-east-1"
INSTANCES = ["db-name-01"]
rds = client("rds", region_name=REGION)
if INSTANCES:
for instance in INSTANCES:
instance_counts = {}
response = rds.describe_db_instances(DBInstanceIdentifier=instance)
dbins = response['DBInstances']
dbin = dbins[0]
dbarn = dbin['DBInstanceArn']
你可以从
rds_dict = self.rds_client.describe_db_instances()
如果您遍历rds_dict
您将获得一个名为DBInstanceArn
的键
我为此使用 boto3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.