CLI reference

更新时间:
复制 MD 格式

The Alibaba Cloud Command Line Interface (CLI) is a general-purpose command-line tool based on OpenAPI. You can use the aliyun command in a command-line Shell to interact with Cloud-native API Gateway and manage your Cloud-native API Gateway resources.

Prerequisites

  1. You have installed the Alibaba Cloud CLI. For more information, see the following documents:

  2. You have configured the Alibaba Cloud CLI. For more information, see Configure credentials.

Note

Cloud Shell is pre-installed with the Alibaba Cloud CLI and automatically configures your identity credentials. No manual configuration is required. You can debug Alibaba Cloud CLI commands in Cloud Shell. For more information, see What is Cloud Shell?.

Permissions

If you use a Resource Access Management (RAM) user or a RAM role to call Cloud-native API Gateway through the CLI, confirm that the RAM user or RAM role has the required access permissions for the resources. For more information, see Identity-based policies.

Generate a CLI command example

  1. Log on to Cloud-native API Gateway API Debugging.

  2. On the API debugging page, search for the API that you want to use in the search box on the left. In the Parameter Configuration section, enter the parameters as described in the API documentation. Click the CLI Example tab to generate a command example with the specified parameters.

    image

    • Click the Run Command image button to open Cloud Shell and quickly debug the command.

    • Click the Copy image button to copy the CLI example to the clipboard. You can then paste it into your local shell tool to run the command.

      • When you copy the CLI example to your local shell tool for debugging, pay attention to the parameter format. For more information about the parameter format for Alibaba Cloud CLI commands, see Parameter format.

      • The example generated by the OpenAPI portal includes the --region option by default. When you run the command on your local machine, the Alibaba Cloud CLI uses the region specified in this option and ignores the region information in your default identity credential configuration and environment variable settings. You can delete or keep this option as needed.

Use the CLI to call Cloud-native API Gateway

For information about the basic usage of the Alibaba Cloud CLI, see Command structure. Before you start, familiarize yourself with the request parameters, response parameters, and other information for the Cloud-native API Gateway OpenAPI. For more information, see API overview.

Note

For different types of API fields, you must follow the parameter format requirements of the Alibaba Cloud CLI. For more information, see Parameter format.

The following examples show how to use the Alibaba Cloud CLI to call an API.

  • Query a list of HTTP APIs based on the HTTP API type and the Cloud-native API Gateway ID

    aliyun apig GET /v1/http-apis --types 'Http,Rest' --gatewayId 'gw-cq2avtllh****'
  • Retrieve basic information about a gateway, such as its associated VPC, vSwitch, and entry point

    aliyun apig GET /v1/gateways/gw-cpv4sqdl*****

Recommendations

When you use the CLI to call APIs for complex tasks, you can improve efficiency by organizing the commands into a shell script before you run them.