I am using aws-cli version 1.7.8 to get the --query output to create one record that is derived from multiple lines. In this case I am trying to get specific information from describe-instances.

In the describe-instances command, we get lines / sections that refer to RESERVATIONS , INSTANCES , and TAGS .

I am able to simply run the new AWS CLI command to get the information from all three lines individually:


aws ec2 describe-instances --instance-ids i-xxxxxxxx --query 'Reservations[*].ReservationId'


aws ec2 describe-instances --instance-ids i-xxxxxxxx --query 'Reservations[*].[Instances[*].[InstanceId,ImageId]]'

TAG line:

aws ec2 describe-instances --instance-ids i-xxxxxxxx --query 'Reservations[].Instances[].[Tags[?Key==Name]]'

I can run these 3 commands, and concatenate the results to form 1 record.

Does anyone know if there is a way I can run this as ONE (1) command, instead of 3 distinct commands?

I've tried PIPE and other forms of syntax, but I'm not able to find a good solution as of yet.

Can I get the equivalent output of these 3 commands from a single command?

  • Run the Windows commands from a powershell prompt in Windows. Then it will return results. – Patrick Parks Jun 2 '17 at 20:04
aws ec2 describe-instances --instance-id i-77777777 \
  --query 'Reservations[*].Instances[*].[InstanceId,ImageId,Tags[*]]' \
  --output text

This command will print Instance Id, AMI ID, Key and Value Tags. You can see more examples here: Controlling Command Output from the AWS Command Line Interface

| improve this answer | |
  • Adding a brief description of what the command is doing might be helpful. – dawud Mar 27 '15 at 20:45
  • would this only work in non-windows based CLI ? I tried it in Windows CMD - it didn't but - in CentOS - it worked. – Naveen Vijay Jun 28 '15 at 23:36
  • Where is some documentation on the query syntax??? – cosbor11 Feb 9 '16 at 20:23
  • Yes. Here you are: docs.aws.amazon.com/cli/latest/userguide/… – Peycho Dimitrov Feb 10 '16 at 21:01
  • The AWS docs only has a few examples. Isn't there a full spec on the syntax? – cosbor11 Feb 12 '16 at 8:20

With Windows (cmd.exe, cmder.exe, etc.), one must use double quotes (") instead of single quotes (') around the query string. Otherwise the console simply prints the path in the query and doesn't even generate an error.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.