This topic describes how to call the DescribeInstances operation by using Alibaba Cloud command-line interface (CLI) to query the details of one or more ECS instances.

Background information

You can call the DescribeInstances operation to query the details of one or more ECS instances. For more information, see DescribeInstances.

When you call an API operation through Alibaba Cloud CLI, make sure that request parameter values of different data types are in required formats. For more information, see Parameter format overview.

Example 1: Query an ECS instance by using its ID

Query information about the ECS instance with the ID of i-bp14a7xie8erwsvo****.

aliyun ecs DescribeInstances --RegionId cn-hangzhou --InstanceIds '["i-bp14a7xie8erwsvo****"]' --output cols=InstanceId,InstanceName,Description,ImageId,Status rows=Instances.Instance[]

Sample response:

InstanceId             | InstanceName | Description | ImageId                | Status
----------             | ------------ | ----------- | -------                | ------
i-bp14a7xie8erwsvo**** | wpdemo       | wp          | m-bp12qhgxbmp5eh02**** | Running

Example 2: Query an ECS instance that is bound with the specified tag

Query information about the ECS instance that is bound with tag owner:zhangsan.

aliyun ecs DescribeInstances --RegionId cn-hangzhou --Tag.1.Key owner --Tag.1.Value zhangsan --output cols=InstanceId,InstanceName,Description,ImageId,Status rows=Instances.Instance[]

Sample response:

InstanceId             | InstanceName            | Description | ImageId                                 | Status
----------             | ------------            | ----------- | -------                                 | ------
i-bp1aq39j2yul5y01**** | namedemo01              | demo01      | m-bp12qhgxbmp5eh02****                  | Stopped
i-bp1dpvr406hq1jnw**** | namedemo02              |  demo01     | centos_7_06_64_20G_alibase_20190711.vhd | Running

Example 3: Query an ECS instance with the specified image ID

Query information about an ECS instance with the image ID of m-bp12qhgxbmp5eh02****.

aliyun ecs DescribeInstances --RegionId cn-hangzhou --ImageId m-bp12qhgxbmp5eh02**** --output cols=InstanceId,InstanceName,Description,ImageId,Status rows=Instances.Instance[]

Sample response:

InstanceId             | InstanceName | Description | ImageId                | Status
----------             | ------------ | ----------- | -------                | ------
i-bp14a7xie8erwsvo**** | demo01       | desc01      | m-bp12qhgxbmp5eh02**** | Running
i-bp1aq39j2yul5y01**** | demo02       | desc02      | m-bp12qhgxbmp5eh02**** | Stopped

Example 4: Query an ECS instance in the specified VPC

Query information about an ECS instance in the VPC with the ID of vpc-bp1vwnn14rqpyiczj**** and the VSwitch ID of vsw-bp1ddbrxdlrcbim46****.

aliyun ecs DescribeInstances --RegionId cn-hangzhou --VpcId vpc-bp1vwnn14rqpyiczj**** --VSwitchId vsw-bp1ddbrxdlrcbim46**** --output cols=InstanceId,InstanceName,ImageId,Status rows=Instances.Instance[]

Sample response:

InstanceId             | InstanceName                      | ImageId                                 | Status
----------             | ------------                      | -------                                 | ------
i-bp14a7xie8erwsvo**** | namedemo01                        | m-bp12qhgxbmp5eh02****                  | Running
i-bp1c271nqm264lwj**** | namedemo02                        | P2VSImageLnx125                         | Running
i-bp18a6ub0vt1tvn1**** | namedemo03                        | centos_7_02_64_20G_alibase_20170818.vhd | Running
i-bp1aq39j2yul5y01**** | namedemo04                        | m-bp12qhgxbmp5eh02****                  | Stopped

Example 5: Query ECS instances by page

Query information about ECS instances on the second page and display five entries per page.

aliyun ecs DescribeInstances --RegionId cn-hangzhou --PageNumber 2 --PageSize 5 --output cols=InstanceId,InstanceName,ImageId,Status rows=Instances.Instance[]

Sample response:

InstanceId | InstanceName | ImageId | Status
----------             | ------------        | -------                                 | ------
i-bp1akazu9o0rm7q0**** | demoname01          | centos_8_0_x64_20G_alibase_20191225.vhd | Running
i-bp134jm1g6kqyiqu**** | demoname02          | m-bp1bc3g3b032o0ja****                  | Running
i-bp17qwke5y0v7hk2**** | demoname03          | centos_7_02_64_20G_alibase_20170818.vhd | Running
i-bp18a6ub0vt1tvn1**** | demoname04          | centos_7_02_64_20G_alibase_20170818.vhd | Running
i-bp1aq39j2yul5y01**** | demoname05          | m-bp12qhgxbmp5eh02****                  | Stopped