The Alibaba Cloud product APIs are divided into RPC API and RESTful API. Most products use RPC style. When you use Alibaba Cloud CLI to call the interface, APIs of different styles have different calling methods.
In Alibaba Cloud CLI, the command line structure is as follows:
aliyun <command> <subcommand> [options and parameters]
- aliyuncli: Alibaba Cloud tool name.
- command: Specify a top-level command.
- Typically, it represents the Alibaba Cloud basic services supported in the command line tool, such as ECS and RDS.
- It also indicates the functional commands of the command line tool. such as help, configure.
- subcommand: Specify an additional subcommand to perform an action.
- options and parameters: Specify the options or API parameter options for controlling the behavior of Alibaba Cloud CLI. The option values can be Number, String, and json structure character string.
When calling the product interface, you must first determine the API style and select
the standard command structure to initiate the call. You can determine the API style
by the checking the following characteristics:
- The API parameter contains the Action field which is the RPC API, and the PathPattern parameter is the RESTful API.
- In general, the calling style of all APIs is uniform within each product.
- Each API only supports a specific style. Passing in the wrong identifier may call
other APIs or cause an
ApiNotFound
error to occur.
Call an RPC API
The basic structure of calling an RPC API by using Alibaba Cloud CLI is as follows:
aliyun <product> <ApiName> [--parameter1 value1 --parameter2 value2 ...]
Example:
aliyun rds DescribeDBInstances --PageSize 50
aliyun ecs DescribeRegions
aliyun rds DescribeDBInstanceAttribute --DBInstanceId xxxxxx
Call a RESTful API
Some Alibaba Cloud products such as Container Service are RESTful API. The basic structure
of calling a RESTful API by using Alibaba Cloud CLI is as follows:
aliyun productcode [GET|PUT|POST|DELETE] <PathPattern> --body "$(cat input.json)"
- GET request
Request structure:
aliyun productcode GET /resource
Example:
aliyun cs GET /clusters
- POST request
Request structure:
aliyun productcode POST /resource --body "$(cat input.json)"
Example:
aliyun cs POST /clusters/<cluster_id>/attach --header "Content-Type=application/json" --body "$(cat attach.json)"
- DELETE request
Request structure:
aliyun productcode DELETE /resource
Example:
aliyun cs DELETE /clusters/ce2cdc26227e09c864d0ca0b2d5*****