All Products
Search
Document Center

Cloud Shell:Use Alibaba Cloud CLI to manage Alibaba Cloud resources

Last Updated:Sep 04, 2024

Alibaba Cloud command-line interface (CLI) is preinstalled in Cloud Shell. Alibaba Cloud CLI is a management tool that is developed based on Alibaba Cloud APIs. You can use Alibaba Cloud CLI to manage your Alibaba Cloud resources.

Alibaba Cloud provides RPC and RESTful APIs. Most cloud services provide the RPC API, for example, Elastic Compute Service (ECS), ApsaraDB RDS, and Server Load Balancer (SLB).

The request method varies based on the architectural style of the API that you want to call. You can determine the API type based on the following descriptions:

  • If an API requires the Action parameter, it is an RPC API. If an API requires the PathPattern parameter, it is a RESTful API.

  • In general, all APIs in a cloud service are of the same type.

Start Cloud Shell

To start Cloud Shell, use one of the following methods:

  • Start Cloud Shell in the Alibaba Cloud Management Console

    In the Alibaba Cloud Management Console, click the Cloud Shell icon in the top navigation bar.

  • Start Cloud Shell as a standalone application

    Enter https://shell.aliyun.com in the address bar of a browser.

    You can open up to five Cloud Shell windows at the same time.

When you start Cloud Shell, take note of the following items:

  • When you connect to Cloud Shell for the first time, a virtual machine (VM) is created. The creation process takes at most 30 seconds.

  • If you open multiple Cloud Shell windows, all the windows are connected to the same VM. The number of VMs does not increase when you open a new Cloud Shell window.

Call RPC API operations in Cloud Shell

Run commands in the following syntax to call RPC API operations in Cloud Shell:

aliyun <ProductCode> <ActionName> [--parameter1 value1 --parameter2 value2]

In the command syntax:

  • ProductCode: specifies the code of the Alibaba Cloud service whose operation you want to call. Examples: ecs for Elastic Compute Service (ECS) and slb for Server Load Balancer (SLB). You can run the aliyun --help command to view the code of an Alibaba Cloud service.

  • ActionName: specifies the name of the API operation that you want to call. For example, you can call an ECS API operation named DescribeInstanceAttribute to view the details of an ECS instance.

  • parameter: specifies the request parameters. For more information, see the API reference of each Alibaba Cloud service.

Example

Run the following command in Cloud Shell to view the configurations of an ECS instance.

Note

Before you run the command, replace i-bp198exxxxxx with an actual instance ID.

aliyun ecs DescribeInstanceAttribute --InstanceId i-bp198exxxxxx | jq 

image

Call RESTful API operations in Cloud Shell

Some Alibaba Cloud services such as Container Service for Kubernetes (ACK) follow the RESTful API standard. The method of calling RESTful API operations is different from that of calling RPC API operations. To call RESTful API operations in Alibaba Cloud CLI, you must send HTTP requests. The following items show the syntax of HTTP requests and provide a sample request for each request method.

  • GET request

    aliyun <ProductCode> GET /<Resource>

    Example

    aliyun cs GET /clusters
  • POST request

    aliyun <ProductCode> POST /<Resource> --body "$(cat input.json)"

    Example

    aliyun cs POST /clusters//attach --header "Content-Type=application/json" --body "$(cat attach.json)"
  • DELETE request

    aliyun <ProductCode> DELETE /<Resource>

    Example

    aliyun cs DELETE /clusters/<cluster-id>

References