Alibaba Cloud CLI is a management tool that is developed based on Alibaba Cloud APIs. You can use Alibaba Cloud CLI to quickly manage Alibaba Cloud resources in your Cloud Shell.
Before you start
Before you use Alibaba Cloud CLI in a Cloud Shell instance, take note of the following items:
Alibaba Cloud CLI is a management tool that is developed based on Alibaba Cloud APIs. For more information, see What is Alibaba Cloud CLI?
To ensure the security of your Alibaba Cloud account and cloud resources, we recommend that you use a Resource Access Management (RAM) identity (RAM user or RAM role) to access Cloud Shell. To access Cloud Shell as a RAM identity, you must grant the required permissions to the RAM identity. For more information, see Identity-based policies.
Due to various factors that affect version synchronization, the pre-installed version of Alibaba Cloud CLI in Cloud Shell is generally upgraded within a few days after the version of Alibaba Cloud CLI is upgraded in the GitHub repository. You can run the
aliyun version
command to view the current version of Alibaba Cloud CLI. You can also manually install any version of Alibaba Cloud CLI.
Procedure
Step 1: Start Cloud Shell
Before you start Cloud Shell, you must log on to the Alibaba Cloud homepage by using a RAM identity that has the required permissions. Cloud Shell automatically configures an identity credential for you based on the identity information of the logon account. To prevent the automatic credential configuration feature from becoming invalid, we recommend that you do not modify or delete the initial configuration file default
.
You can use one of the following methods to start Cloud Shell:
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.
When you connect to Cloud Shell for the first time, a virtual machine (VM) is created. The creation process takes at most 30 seconds.
You can open multiple Cloud Shell windows based on your business requirements. A maximum of five Cloud Shell windows can be opened at the same time. All the windows are connected to the same VM. The number of VMs does not increase when you open a new Cloud Shell window.
For more information, see What is Cloud Shell?
Step 2: Obtain CLI commands
Automatically generate CLI commands
OpenAPI Explorer allows you to generate all commands of Alibaba Cloud CLI online. We recommend that you use this method to obtain the sample commands that you require. For more information, see Generate a command.
In the left-side search box of the Debugging page, search for the API operation that you want to call. On the Parameters tab of the API operation, specify the parameters based on the API reference. Click the CLI Example tab on the right side to view the generated sample command that contains the specified parameters.
Click Run Command in CloudShell (the icon) to start Cloud Shell and debug the command in Cloud Shell.
Click Copy (the icon) to copy the sample CLI command to a clipboard and then paste it into Cloud Shell to run the command.
Manually write commands
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.
For more information, see Call RPC API and RESTful API.
Obtain help information
Run the following command in Cloud Shell to view the help information about a cloud service:
aliyun <ProductCode> --help
For example, run the following command to view the help information about the ECS APIs:
aliyun ecs --help
Run the following command in Cloud Shell to view the help information about an API operation:
aliyun <ProductCode> <ApiName> --help
For example, run the following command to view the help information about the
DescribeInstanceAttribute
operation of ECS:aliyun ecs DescribeInstanceAttribute --help
Step 3: Run commands in Cloud Shell
As shown in the following figure, run the CreateInstance
command of Elastic Compute Service in Cloud Shell to create a pay-as-you-go ECS instance.
References