What I'm trying to achieve
I want to extract the volume ID for the root block device using describe-instances
.
What I tried so far
aws ec2 describe-instances --filters "Name=tag:Backup,Values=True" --query 'Reservations[].Instances[].{Name: Tags[?Key==`Name`].Value | [0], Id: InstanceId, Block: BlockDeviceMappings[?DeviceName==RootDeviceName].Ebs.VolumeId, Test: RootDeviceName}'
What's not working
Several things:
Ebs.VolumeId
is not the direct descendant ofDeviceName
, it is descending fromBlockDeviceMappings
.RootDeviceName
is not a descendant ofBlockDeviceMappings
.
So when I'm trying to pull the RootDeviceName
and search the VolumeId
accordingly I'm getting a blank field (Block: is for testing and irrelevant to the case).
The first 2 fields are correct.
Thanks in advance!