All Products
Search
Document Center

Alibaba Cloud CLI:Aggregate the results of paging operations

Last Updated:May 13, 2025

By default, paging operations return the result only on a single page. To obtain the complete results of a paging operation, you can use the --pager option to aggregate the paging results.

Fields and descriptions

You can use the --pager option in Alibaba Cloud CLI to aggregate the array results of paging operations. This option contains the following fields, which must correspond to the fields in the results returned by the operation.

Field

Description

PageNumber

The number of the page to return. By default, the field value is automatically synchronized between the request and response.

PageSize

The maximum number of entries to return on each page. By default, the field value is automatically synchronized between the request and response.

TotalCount

The total number of entries. By default, the field value is automatically synchronized between the request and response.

NextToken

A pagination token. It can be used in the next request to retrieve a new page of results. By default, the field value is automatically synchronized between the request and response.

path

By default, the path is automatically identified. You can manually specify an array in JMESPath.

Scenario

Note

Some operations support the maxResult parameter, which specifies the maximum number of entries to return per query. If you specify a value smaller than expected, the request frequency and processing time may be greatly increased. To optimize the query efficiency, we recommend that you specify a proper value for maxResult when you use the --pager option in Alibaba Cloud CLI.

  1. 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
  2. Sample response (partial):

    {
        "PageNumber": 1,
        "TotalCount": 4,
        "PageSize": 10,
        "RequestId": "6EA82E70-9750-4A97-A738-E021D8A57F07",
        "Instances": {
            "Instance": [
                {    
                    "InstanceId": "i-m5edv0cqkr9hawls****"
                    "ImageId": "win2012r2_64_dtc_9600_zh-cn_40G_alibase_20190318.vhd",
                    "SerialNumber": "f06857e8-7f3c-443a-9f88-8e84eb51****",
                    "Cpu": 1,
                    "Memory": 2048,
                    "DeviceAvailable": true,
                    "SecurityGroupIds": {
                        "SecurityGroupId": [
                            "sg-bp1fgviwol82z8ap****"
                        ]
                    }
                }
            ]
        }
    }
  3. Run the following command to query the instance ID on each page.

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

    If the field value is the same as the default value, the field can be skipped and you only need to configure the --pager option.

  4. Sample aggregation results (partial):

    Note

    Only the aggregated fields are returned. If you need to filter specific fields, set the filtering path to the aggregated path in JMESPath. For more information, see Extract parameters and tabulate output.

    {
        "Instances": {
            "Instance": [
                {    
                    "InstanceId": "i-m5edv0cqkr9hawls****"
                    "ImageId": "win2012r2_64_dtc_9600_zh-cn_40G_alibase_20190318.vhd",
                    "SerialNumber": "f06857e8-7f3c-443a-9f88-8e84eb51****",
                    "Cpu": 1,
                    "Memory": 2048,
                    "DeviceAvailable": true,
                    "SecurityGroupIds": {
                        "SecurityGroupId": [
                            "sg-bp1fgviwol82z8ap****"
                        ]
                    }
                }
            ]
        }
    }