【发布时间】:2016-07-29 00:54:22
【问题描述】:
原因:我正在编写与 AWS 提供的预留利用率报告类似的报告(但不同)
我有我的实例列表。
我有我的预订清单。
我想把它们联系起来。我知道许多实例可能共享相同的保留。但我应该能够链接它们,但只有我知道特定实例的 reservation_id。但是......如何获取实例的reservation_id????检查了文档,只能找到命令行工具来获取此信息。
一些代码
import boto3
client = boto3.client('ec2')
region = "us-east-1"
ec2 = boto3.resource("ec2", region_name=region)
ec2_list = list()
for instance in ec2.instances.all():
name = 'Un-named'
for tag in instance.tags:
if tag['Key'].upper() == 'NAME':
name = tag['Value'] # nothing called tag['reservation_id']
ec2_list.append((name, instance.id, instance.public_dns_name,
instance.placement['AvailabilityZone'],
instance.instance_type))
reservations = client.describe_reserved_instances()
【问题讨论】: