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