我正在尝试检索与实例关联的所有卷。
if volume.attachment_state() == 'attached':
volumesinstance = ec2_connection.get_all_instances()
ids = [z for k in volumesinstance for z in k.instances]
for s in ids:
try:
tags = s.tags
instance_name = tags["Name"]
print (instance_name)
except Exception as e:
print e
但是,它没有按预期工作。
答案 0 :(得分:0)
您可以在get_all_instances方法
中添加过滤器 像这样:filter = {'block-device-mapping.volume-id': volume.id}
volumesinstance = ec2_connection.get_all_instances(filters=filter)
ids = [z for k in volumesinstance for z in k.instances]
for s in ids:
try:
tags = s.tags
instance_name = tags["Name"]
print (instance_name)
except Exception as e:
print e