Boto3 get EC2 instance's volume

前端 未结 5 556
既然无缘
既然无缘 2021-01-14 10:00

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          


        
5条回答
  •  有刺的猬
    2021-01-14 10:32

    An iterator is returned by ec2.Instance.volumesCollection

    You can extract the volume ids with code like this

    volume_id_list=[]
    for item in instance.volumes.all():
      volume_id_list.append(item.id)
    

    then volume_id_list[0] contains the first disk, volume_id_list[1] the second etc

    See https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Instance.volumes

提交回复
热议问题