Issue
I am trying to combine the following 2 commands into 1
aws ec2 describe-instances --query Reservations[].Instances[].State[].{InstanceState:Name} --output table
aws ec2 describe-instances --query Reservations[].Instances[].Tags[].{InstanceName:Value} --output table
My last ditch plan is to call both separately but I am sure there is a way to do this in 1 line. The closet I got was 1 table with the incorrect instance name using the command below.
aws ec2 describe-instances --query Reservations[].Instances[].State[].{InstanceState:Name,InstanceName:Tags.Value} --output table
Sample output
Describe Instances
InstanceName | InstanceState
Name A | running
Name B | stopped
Does anyone know what I am missing?
Solution
There can be more than one tag but only one value for other attributes like instance state, so get the first element in the tags assuming it always has the name for all instances. I tried the following and it worked fine for me:
aws ec2 describe-instances --query Reservations[].Instances[].[State.Name,Tags[0].Value] --output table
Answered By - helloV Answer Checked By - Senaida (WPSolving Volunteer)