When you use Alibaba Cloud CLI to call paging operations of Alibaba Cloud services, only the results on the first page are returned by default. To obtain all results, you can use Alibaba Cloud CLI to aggregate the results.
Description of the --pager option
You can use --pager
option to aggregate the results of the ARRAY type of a paging operation. The following table describes the parameters contained in the --pager option:
Parameter | Description |
PageNumber | Corresponds to the parameter that indicates the page number in the response of a paging operation. Default value: |
PageSize | Corresponds to the parameter that indicates the maximum number of results per page in the response of a paging operation. Default value: |
TotalCount | Corresponds to the parameter that indicates the total number of results in the response of a paging operation. Default value: |
path | You can manually specify the JMESPath path of the data of the ARRAY type to be aggregated due to the diversity of the results of API operations. Note By default, the |
Scenario
The
DescribeInstances
operation of Elastic Compute Service (ECS) is a paging operation. Run the following command. By default, only the results on the first page of the instance list are returned.aliyun ecs DescribeInstances
Sample response (partially truncated):
{ "PageNumber": 1, "TotalCount": 4, "PageSize": 10, "RequestId": "6EA82E70-9750-4A97-A738-E021D8A57F07", "Instances": { "Instance": [ { "ImageId": "win2012r2_64_dtc_9600_zh-cn_40G_alibase_20190318.vhd", "SerialNumber": "f06857e8-7f3c-443a-9f88-8e84eb5163c7", "Cpu": 1, "Memory": 2048, "DeviceAvailable": true, "SecurityGroupIds": { "SecurityGroupId": [ "sg-bp1fgviwol82z8ap348n" ] } } ] } }
Sample commands
Run the following command to return the instance information on all pages:
aliyun ecs DescribeInstances --pager PageNumber=PageNumber PageSize=PageSize TotalCount=TotalCount path=Instances.Instance
The response parameters of this operation are the same as the default values of the parameters contained in the --pager option. Therefore, you can omit the parameters in the --pager option when you use the
--pager
option. Simplified command:aliyun ecs DescribeInstances --pager
Sample output (partially truncated):
NoteThe aggregated output contains only aggregated parameters. If you use the filtering feature to extract the parameters that you need, the path of the extracted parameter is the JMESPath path after the aggregation. For more information, see Extract parameters and tabulate output.
{ "Instances": { "Instance": [ { "ImageId": "win2012r2_64_dtc_9600_zh-cn_40G_alibase_20190318.vhd", "SerialNumber": "f06857e8-7f3c-443a-9f88-8e84eb5163c7", "Cpu": 1, "Memory": 2048, "DeviceAvailable": true, "SecurityGroupIds": { "SecurityGroupId": [ "sg-bp1fgviwol82z8ap348n" ] } } ] } }