This topic describes how to call the DescribeInstances operation by using Alibaba Cloud 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. We recommend that you read the description of the operation before you call the operation. 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 the details of an ECS instance based on the ID of the instance

Query information about the ECS instance whose ID is 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 the details of instances that are bound with the specified tag

Query information about the instances that are bound with the owner:zhangsan tag.

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 the details of ECS instances with the specified image ID

Query information about ECS instances with the m-bp12qhgxbmp5eh02**** image ID.

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 the details of instances in the specified VPC

Query information about ECS instances in the vpc-bp1vwnn14rqpyiczj**** VPC. The ID of the VSwitch in the VPC is 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 the details of ECS instances by page

Query the five ECS instance entries on the second 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