All Products
Search
Document Center

Alibaba Cloud CLI:Aggregation of paging interface results

Last Updated:Nov 16, 2023

By default, only the results on the first page are returned when calling the paging interface of each cloud product using Alibaba Cloud CLI. If you require all the results, you can use the Alibaba Cloud CLI to aggregate the results.

--pager overview

You can use --pager option to aggregate the results of the array class of the paging interface. This option contains the following four fields:

Field Name

Description

PageNumber

Corresponds to the field that describes the current page number in the returned results of the API. Default value: PageNumber.

PageSize

Corresponds to the field that describes the maximum number of results returned per page in the API return results. Default value: PageSize.

TotalCount

Corresponds to the field that describes the total number of rows in the returned results of the API. Default value: TotalCount.

path

Because of the diversity of returned results by the API, you can manually specify the JMESPath path of the array type to be aggregated.

Note

By default, the --pager option automatically recognizes the array type data in the result.

Scenario

The DescribeInstances interface of ECS products is a paging interface. Run the following command. By default, this interface only returns the first page of the instance information list.

aliyun ecs DescribeInstances

The system displays output similar to the following (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"
                                        ]
                                }
                        }
                ]
        }
}

Solution

Run the following command to get the instance information on all pages of the list:

aliyun ecs DescribeInstances --pager
Note

Because the values returned by this interface comply with the default values of the sub-fields, all the sub-fields are omitted in the preceding command. The complete command format is as follows:

aliyun ecs DescribeInstances --pager PagerNumber=PagerNumber PageSize=PageSize TotalCount=TotalCount path=Instances.Instance

The following aggregation result (partially truncated) is displayed:

{
        "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"
                                        ]
                                }
                        }
                ]
        }
}
Note

The aggregated output only contains aggregated fields. If you use the filtering function to get the fields you need to know, the path of the filtering field is the JMESPath path after the aggregation. For more information, see Filter results and tabulate output.