Scenario / Questions
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 command, we get lines / sections that refer to
INSTANCES , and
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]]'
aws ec2 describe-instances --instance-ids i-xxxxxxxx --query 'Reservations.Instances.[Tags[?Key==
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?
Find below all possible solutions or suggestions for the above questions..
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
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.
Disclaimer: This has been sourced from a third party syndicated feed through internet. We are not responsibility or liability for its dependability, trustworthiness, reliability and data of the text. We reserves the sole right to alter, delete or remove (without notice) the content in its absolute discretion for any reason whatsoever.