Boto3 获取 EC2 实例的卷 [英] Boto3 get EC2 instance's volume

查看:29
本文介绍了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

谢谢,比照.

推荐答案

它只是一个可迭代的对象

It's just an iterable of objects so

for v in volumes:
    print(v.id)

如果你想得到一个id列表:

if you want to get a list of id :

l = [v.id for v in volumes]

这篇关于Boto3 获取 EC2 实例的卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆