获取AWS AMI属性

时间:2012-08-22 11:14:47

标签: python amazon-ec2 boto ec2-ami

我有一个AMI列表,我通过创建一个boto连接获得:

conn_eu = boto.ec2.connect_to_region('eu-west-1')
images = conn_eu.get_all_images(owners=['me'])

我希望能够看到这些AMI的属性。属性,例如描述,名称和图像ID。

2 个答案:

答案 0 :(得分:2)

看了image.py后,我意识到我可以做到: image.id获取图片ID 和image.description获取图像描述

答案 1 :(得分:2)

以下是每个Print all properties of a Python Class boto.ec2.image.Image 对象的所有属性:

from boto.ec2 import connect_to_region
ec2_connection = connect_to_region("us-west-2",
          aws_access_key_id="...",
          aws_secret_access_key="...")
images = ec2_connection.get_all_images(image_ids=["ami-xxxxxxxxx"])
for k in vars(images[0]).keys():
       print "{0}".format(k)

(或者,也可以使用打印值):

for k,v in vars(images[0]).iteritems():
       print "{0}:{1}".format(k,v)

root_device_type ramdisk_id id owner_alias billing_products tags platform state location type virtualization_type sriov_net_support architecture description block_device_mapping kernel_id owner_id is_public instance_lifecycle creationDate name hypervisor region item connection root_device_name ownerId product_codes