Boto3获取EC2实例的音量 [英] Boto3 get EC2 instance's volume
本文介绍了Boto3获取EC2实例的音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用boto 3获取AWS实例的volume-id列表,我正在获得某种收集管理器,但是我不知道如何将数据放入内部.
I am trying to get volume-id list of aws instance using boto 3, I am getting sort of collection manager but I don't know how to get the data inside.
import boto3
ec2 = boto3.resource('ec2', region_name='us-west-2')
instance = ec2.Instance('i-xxxxxx')
volumes = instance.volumes.all()
print volumes
我得到的答案是:
ec2.Instance.volumesCollection(ec2.Instance(id='i-xxxxxx'), ec2.Volume)
我如何使用"ec2.Volume"获取卷ID
How I am using the "ec2.Volume" to get the volume id
谢谢, Cfir.
推荐答案
它只是对象的可迭代对象,所以
It's just an iterable of objects so
for v in volumes:
print(v.id)
如果要获取ID列表:
l = [v.id for v in volumes]
这篇关于Boto3获取EC2实例的音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文