#/usr/bin/python
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)
它只列出了音量总大小和status(available,in-use...)
,我该怎么做到?
答案 0 :(得分:3)
假设您使用的是 Python 2.7 :
for volume in volumes:
print volume.size, volume.state
<强>输出强>
16 in-use
500 in-use
对于其他属性:
dir(volume)
[u&#39; attach_to_instance&#39;,u&#39; attachments&#39;, u&#39; availability_zone&#39;,u&#39; create_snapshot&#39;,u&#39; create_tags&#39;, 你&#39; create_time&#39;,你&#39;删除&#39;,u&#39; describe_attribute&#39;,u&#39; describe_status&#39;, 你&#39; detach_from_instance&#39;,u&#39; enable_io&#39;,u&#39;加密&#39;, &#39; get_available_subresources&#39;,u&#39; id&#39;,u&#39; iops&#39;,u&#39; kms_key_id&#39;,&#39; load&#39;, &#39; meta&#39;,u&#39; modify_attribute&#39;,&#39; reload&#39;,u&#39; size&#39;,u&#39; snapshot_id&#39;, 你快照&#39;,你&#39;你&#39;标签&#39;,你&#39; volume_id&#39;,你&#39; volume_type&#39;]