CLI reference

Updated at:
Copy as MD

Alibaba Cloud CLI is an open source tool built on Alibaba Cloud SDK for Go. You can run aliyun commands to interact with API Gateway and manage your API Gateway resources.

Prerequisites

  1. Alibaba Cloud CLI is installed. For more information, see the following topics:

  2. Alibaba Cloud CLI is configured. For more information, see Configure profiles.

Permissions

If you use a Resource Access Management (RAM) user or RAM role to interact with API Gateway by using the CLI, make sure that the RAM user or RAM role has the required permissions. For more information, see Identity-based permission policies.

Generate a CLI command

  1. Go to the Debugging page.

  2. In the left-side search box, search for the API operation that you want to call. On the Parameters tab in the middle of the page, specify the parameters based on the API documentation displayed on the right. Then, click the CLI Example tab on the right to generate a sample command with your parameter configurations.

    The generated command looks like this: aliyun cloudapi DescribeInstances --region cn-hangzhou --InstanceId 'apigateway-hz-xxx' --Language zh --EnableTagAuthorization false. The parameter values in the command match the values you entered on the Parameters tab.

    • Click the image icon to run and debug the command in Cloud Shell. For more information, see What is Cloud Shell?

    • Click the image icon to copy the CLI command to the clipboard and paste it into your local shell.

      • Pay attention to the parameter formats when you copy and paste the CLI command to your local shell. For more information about the required formats, see Parameter formats.

      • By default, OpenAPI Explorer adds the --region option to the generated CLI command. When you copy the command to your local shell, Alibaba Cloud CLI uses the specified region instead of the region in your default credential configurations or environment variable settings. You can delete or retain this option based on your business requirements.

Use the CLI to invoke API Gateway

For more information, see Command syntax. Before you call API Gateway operations, make sure that you understand the request and response parameters. For more information, see List of API operations by function.

Note

Parameters of different data types must comply with the format requirements of Alibaba Cloud CLI. For more information, see Parameter formats.

The following examples show how to call API Gateway operations by using Alibaba Cloud CLI:

  • Query the details of Serverless and dedicated instances in the China (Hangzhou) region

    aliyun cloudapi DescribeInstances --region cn-hangzhou
  • Query the details of an API group:

    aliyun cloudapi DescribeApiGroup --region cn-hangzhou --GroupId 2d6e4d64c*******

Usage notes

To perform a complex task by calling multiple API operations, we recommend that you compile the commands into a shell script to improve efficiency.