Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...





Code Block
titleinstance 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 )


Code Block
titlewith 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                           |||


show instance name, id and type


Code Block
titlename , type and id
aws ec2 describe-instances  --query 'Reservations[].Instances[].{Name:Tags[?Key==`Name`].Value[] | [0],InstanceId:InstanceId,Inst
anceType:InstanceType}'  --filter "Name=instance-state-name,Values=running" --no-verify

-------------------------------------------------------------------
|                        DescribeInstances                        |
+----------------------+---------------+--------------------------+
|      InstanceId      | InstanceType  |          Name            |
+----------------------+---------------+--------------------------+
|  i-051cfe892501c68e5 |  t2.nano      |  ixVPC-Ubuntu1-instance  |
|  i-089af23ab4698867b |  c3.xlarge    |  ixVPC-vSRX1             |
+----------------------+---------------+--------------------------+


Without the :  " | [0]"
------------------------
aws ec2 describe-instances  --query 'Reservations[].Instances[].{Name:Tags[?Key==`Name`].Value[],InstanceId:InstanceId,InstanceTy
pe:InstanceType}'  --filter "Name=instance-state-name,Values=running" --no-verify

-----------------------------------------
|           DescribeInstances           |
+----------------------+----------------+
|      InstanceId      | InstanceType   |
+----------------------+----------------+
|  i-051cfe892501c68e5 |  t2.nano       |
+----------------------+----------------+
||                Name                 ||
|+-------------------------------------+|
||  ixVPC-Ubuntu1-instance             ||
|+-------------------------------------+|
|           DescribeInstances           |
+----------------------+----------------+
|      InstanceId      | InstanceType   |
+----------------------+----------------+
|  i-089af23ab4698867b |  c3.xlarge     |
+----------------------+----------------+
||                Name                 ||
|+-------------------------------------+|
||  ixVPC-vSRX1                        ||
|+-------------------------------------+|



ec2 instance status


Code Block
titlestaus
collapsetrue
Original:
--------

aws ec2 descri
be-instance-status --no-verify --instance-ids i-04e429cb6e26b6dd1

-----------------------------------------------
|           DescribeInstanceStatus            |
+---------------------------------------------+
||             InstanceStatuses              ||     InstanceStatuses[]
|+-------------------+-----------------------+|
|| AvailabilityZone  |      InstanceId       ||
|+-------------------+-----------------------+|
||  us-west-2c       |  i-04e429cb6e26b6dd1  ||
|+-------------------+-----------------------+|
|||              InstanceState              |||     InstanceStatuses[].InstanceState[]
||+----------------+------------------------+||
|||      Code      |         Name           |||
||+----------------+------------------------+||
|||  16            |  running               |||
||+----------------+------------------------+||
|||             InstanceStatus              |||     InstanceStatuses[].InstanceStatus[]
||+-------------------------+---------------+||
|||  Status                 |  ok           |||
||+-------------------------+---------------+||
||||                Details                ||||     InstanceStatuses[].InstanceStatus[].Details[]
|||+-----------------------+---------------+|||
||||         Name          |    Status     ||||
|||+-----------------------+---------------+|||
||||  reachability         |  passed       ||||
|||+-----------------------+---------------+|||
|||              SystemStatus               |||     InstanceStatuses[].SystemStatus[]
||+-------------------------+---------------+||
|||  Status                 |  ok           |||
||+-------------------------+---------------+||
||||                Details                ||||     InstanceStatuses[].SystemStatus[].Details[]
|||+-----------------------+---------------+|||
||||         Name          |    Status     ||||
|||+-----------------------+---------------+|||
||||  reachability         |  passed       ||||
|||+-----------------------+---------------+|||




With the filter:
-----------------

aws ec2 describe-instance-status --no-verify --instance-ids i-04e429cb6e26b6dd1 --query 'InstanceStatuses[].InstanceStatus[].[Status]'


------------------------
|DescribeInstanceStatus|
+----------------------+
|  ok                  |
+----------------------+