https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output.html
instance id and instance name ( Tags ) aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId, Tags[?Key==`Name`].Value[] | [0]]' --output text --no-verify i-0947d5f8513cff6ed ixVPC-vSRX1 i-0ae9837801fcda4ce ixVPC-Ubuntu1-instance Only InstanceId ---------------- aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId]' --output text --no-verify i-0947d5f8513cff6ed i-0ae9837801fcda4ce Only Tags ---------- aws ec2 describe-instances --query 'Reservations[].Instances[].[Tags[?Key==`Name`].Value[] | [0]]' --output text --no-verify ixVPC-vSRX1 ixVPC-Ubuntu1-instance no output: --output text -------------------------- aws ec2 describe-instances --query 'Reservations[].Instances[].[Tags[?Key==`Name`].Value[] | [0]]' --no-verify ---------------------------- | DescribeInstances | +--------------------------+ | ixVPC-vSRX1 | | ixVPC-Ubuntu1-instance | +--------------------------+ | |
query +with column names ( any names ) | with column name aws ec2 describe-instances --query 'Reservations[].Instances[].{InstanceId:InstanceId,InstanceType:InstanceType}' --no-verify ----------------------------------------- | DescribeInstances | +----------------------+----------------+ | InstanceId | InstanceType | +----------------------+----------------+ | i-0947d5f8513cff6ed | c3.xlarge | | i-0ae9837801fcda4ce | t2.nano | +----------------------+----------------+ InstanceId:InstanceId <name of the column>:<name of the row> InstanceType:InstanceType <name of the column>:<name of the row> ------------------------------------------------------------------------------------ | DescribeInstances | +----------------------------------------------------------------------------------+ || Reservations || |+---------------------------------+----------------------------------------------+| || OwnerId | 296119820525 || || ReservationId | r-0fe954f096ff2ba8e || |+---------------------------------+----------------------------------------------+| ||| Instances ||| ||+------------------------+-----------------------------------------------------+|| ||| AmiLaunchIndex | 0 ||| ||| Architecture | x86_64 ||| ||| ClientToken | ||| ||| EbsOptimized | False ||| ||| EnaSupport | True ||| ||| Hypervisor | xen ||| ||| ImageId | ami-005bdb005fb00e791 ||| ||| InstanceId | i-0ae9837801fcda4ce ||| <<<<<<<<<< InstanceId row ||| InstanceType | t2.nano ||| <<<<<<<<<<<<<<<< InstanceType row ||| KeyName | terraformkeypairuswest2 ||| ||| LaunchTime | 2019-03-25T13:41:36.000Z ||| |