Issue
I'm trying to filter my output for describe-instances tot show the following:
- instanceId
- Device + Volume
- Tag[Key==Name]
The expression I have is
aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query "Reservations[*].Instances[].[InstanceId, BlockDeviceMappings[*].{DeviceName:DeviceName,VolumeName:Ebs.VolumeId}, Tags[*]]"
But this gives me output where all the tags are showing. How can I change this to only the "Name" tag?
Solution
You are looking for a JMESPath Filter Expression. Try this:
aws ec2 describe-instances \
--filters Name=instance-state-name,Values=running \
--query 'Reservations[*].Instances[].[InstanceId, BlockDeviceMappings[*].{DeviceName:DeviceName,VolumeName:Ebs.VolumeId}, Tags[?Key==`Name`]]'
Answered By - ataylor Answer Checked By - Pedro (WPSolving Volunteer)