All Products
Search
Document Center

Alibaba Cloud CLI:Command syntax

最終更新日:Dec 18, 2024

The APIs of Alibaba Cloud services are classified into two styles: remote procedure call (RPC) and resource-oriented architecture (ROA). Most services use the RPC style. When you use Alibaba Cloud CLI to call an API operation, the call method varies based on the API style.

Syntax of common commands

In Alibaba Cloud CLI, you can use the following syntax to run common commands:

aliyun <command> <subcommand> [options and parameters]

  • command: the top-level command.

    • You can specify the code of an Alibaba Cloud service supported by Alibaba Cloud CLI, such as ecs or rds.

    • You can also specify an Alibaba Cloud CLI command, such as help or configure.

  • subcommand: the operation that you want to perform.

    • For more information about the subcommands supported if the command parameter is set to configure, see Profile-related commands.

    • If the command parameter is set to the code of an Alibaba Cloud service, the subcommands supported are the API operations of the Alibaba Cloud service. For more information about the API operations of Alibaba Cloud services, see the "Step 2: Search for an API operation for which you want to generate a CLI command" section of the Generate and run CLI commands topic.

  • options and parameters: the options or API parameters that are used in Alibaba Cloud CLI commands. The value of an option or a parameter can be a number, string, or JSON array. For more information, see Parameter formats.

Syntax of commands used to call API operations

Check the API style

The APIs of Alibaba Cloud services are classified into two styles: RPC and ROA. Most services use the RPC style. Before you call an API operation, you must check the API style and then initiate the call based on the corresponding syntax. You can use one of the following methods to check the API style:

  • Go to the documentation of the Alibaba Cloud service whose API you want to call and view the API style in the List of operations by function topic of the Development reference section.

  • Add --help after the code of the Alibaba Cloud service whose API you want to call in the command to obtain the API operations of the Alibaba Cloud service. If a brief description is returned, the API style is RPC. If the PathPattern parameter that indicates the request path is returned, the API style is ROA. For more information, see the "Query the API operations of an Alibaba Cloud service" section of the Use the help command topic.

  • Add --help after the name of an API operation in the command to obtain the parameters of the API operation. If the Method and PathPattern parameters are returned in addition to the parameters of the API operation, the API style is ROA. The Method parameter indicates the request method and the PathPattern parameter indicates the request path of the API operation. For more information, see the "Query the parameters of an API operation" section of the Use the help command topic.

In most cases, all API operations of a service use the same API style. Each API supports only one style. For more information about the RPC and ROA styles, see API styles.

Call an RPC API operation

Syntax

You can use the following syntax to run a command that is used to call an RPC API operation by using Alibaba Cloud CLI:

aliyun <product> <APIName> [--parameter1 value1 --parameter2 value2 ...]
  • ProductCode: the code of the Alibaba Cloud service whose API you want to call. For example, the code of Elastic Compute Service (ECS) is ecs.

  • APIName: the name of the API operation that you want to call. For example, you can call the DescribeRegions operation of Elastic Compute Service.

  • --parameter: the request parameters that you must specify. You can view the details of the request parameters in the API reference of each Alibaba Cloud service.

  • You can use the --help command to obtain the help information about the preceding parameters. For more information, see Use the help command.

Examples

  • In this example, the DescribeRegions operation of Elastic Compute Service is called. For more information, see DescribeRegions.

    aliyun ecs DescribeRegions
  • In this example, the DescribeInstanceAttribute operation of Elastic Compute Service is called. For more information, see DescribeInstanceAttribute.

    aliyun rds DescribeInstanceAttribute --InstanceId 'i-uf6f5trc95ug8t33****'

Call an ROA API operation

Syntax

You can use the following syntax to run a command that is used to call an ROA API operation by using Alibaba Cloud CLI:

 aliyun <ProductCode> <Method> <PathPattern> --body <RequestBody>
  • ProductCode: the code of the Alibaba Cloud service whose API you want to call. For example, the code of Container Service for Kubernetes (ACK) is cs.

  • Method: the request method. Common request methods include GET, PUT, POST, and DELETE. You can select an appropriate request method based on the API reference.

  • PathPattern: the request path. You can specify a valid request path based on the API reference.

  • RequestBody: the request body. The value is a JSON string. You can edit the JSON string based on the API reference, or reference a JSON file.

  • You can use the --help command to obtain the help information about the preceding parameters. For more information, see Use the help command.

Examples

GET request

In this example, the DescribeClusterDetail operation of Container Service for Kubernetes is called. For more information, see DescribeClusterDetail.

aliyun cs GET /clusters/{cluster_id}

PUT request

In this example, the ModifyCluster operation of Container Service for Kubernetes is called. For more information, see ModifyCluster.

aliyun cs PUT /api/v2/clusters/{ClusterId} --header "Content-Type=application/json" --body "$(cat input.json)"

POST request

In this example, the CreateCluster operation of Container Service for Kubernetes is called. For more information, see CreateCluster.

aliyun cs POST /clusters --header "Content-Type=application/json" --body "$(cat create.json)"

DELETE request

In this example, the DeleteClusterNodepool operation of Container Service for Kubernetes is called. For more information, see DeleteClusterNodepool.

aliyun cs DELETE /clusters/{ClusterId}/nodepools/{NodepoolId}