简体   繁体   中英

How to list all volume-ids associated with ec2 instance using ruby aws-sdk?

I am stuck on listing all the volumes and volume-ids associated to ec2 instance. I am seeking to list the ebs-optimized volume attached to it.

ec2 = AWS::EC2.new(
 :access_key_id => 'QWERTYUIOPASD',
 :secret_access_key => 'qwertyuiasdfghzxcvbn1234567'
)

ec2.instances["i-qwerty1"].block_device_mappings

It is only returning the root volume's id.

{"/dev/sda1"=><AWS::EC2::Attachment volume_id:vol-123456 instance_id:i-qwerty1 device:/dev/sda1>} ```

Is there any method which can list all associated volume-ids.

I even tried using ec2 internal meta-data, which only provided ami volume details

$ curl -L http://169.254.169.254/latest/meta-data/block-device-mapping
$ ami

Also the instance is being managed in Chef. I even checked ohai data for the instance. I can't find the list of volumes attached to it.

Please help!! :)

I have solved it.

We can use

ec2.instances[JSON.parse(<Node>.to_s).automatic.ec2.instance_id].block_device_mappings["/dev/sda1"].volume.id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM