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?
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`]]'
This worked for me
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query 'Reservations[].Instances[].[ [Tags[?Key==`Name`].Value][0][0],[Tags[?Key==`tag_component_name`].Value][0][0] ]' --output json --profile myprofile --region us-east-1
Make sure to change the --output, --profile and --region paramaters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With