...
https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output.html
|
|
---|
|
Code Block |
---|
title | instance id and instance name ( Tags ) |
---|
| aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId, Tags[?Key==`Name`].Value[] | [0]]' --output text --no-verify
|
|
C:\Program Files\Amazon\AWSCLI\.\botocore\vendored\requests\packages\urllib3\connectionpool.py:768: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
i-0947d5f8513cff6ed ixVPC-vSRX1
i-0ae9837801fcda4ce ixVPC-Ubuntu1-instancei-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 |
---|
| 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 |
---|
| 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 |
---|
| Original:
--------
aws ec2 describe-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 |
+----------------------+
With output: text
-----------
aws ec2 describe-instance-status --no-verify --instance-ids i-01744da369a4b2299 --query 'InstanceStatuses[].InstanceStatus[].[Status]' --output text
impaired
|
|