Alibaba Cloud CLI is a general-purpose command-line tool built on OpenAPI Explorer. You can use it to automate the management and maintenance of ENS resources, including calling ENS API operations.
Before you begin
Familiarize yourself with Alibaba Cloud CLI. For more information, see What is Alibaba Cloud CLI?
Install Alibaba Cloud CLI
Alibaba Cloud CLI is available for Windows, Linux, and macOS. Select the installation package for your operating system:
You can also use Cloud Shell to debug Alibaba Cloud CLI commands. For more information, see What is Cloud Shell?
Configure Alibaba Cloud CLI
An Alibaba Cloud account has the permissions to manage and access the APIs of all Alibaba Cloud services. If you use an Alibaba Cloud account to call API operations, security risks may arise. We recommend that you create and use a Resource Access Management (RAM) user to call API operations or perform routine O&M operations.
Before you use Alibaba Cloud CLI, configure your identity credentials and region ID. Alibaba Cloud CLI supports various credential types. For more information, see Credential types. This example uses AccessKey credentials.
-
Create a RAM user and grant the RAM user the required permissions. For more information, see Create a RAM user and Grant permissions to a RAM user.
ImportantFor this example, you must grant the
AliyunENSFullAccesspolicy to the RAM user. This policy grants full control to query and modify ENS instances. You can also grant theAliyunENSReadOnlyAccesspolicy or a custom policy as needed. For more information, see Reference for custom policies of ENS. -
After creating and authorizing the RAM user, create an AccessKey pair for it. Record the
AccessKey IDandAccessKey Secretfor credential configuration. For more information, see Create an AccessKey pair. -
Obtain and record the ID of an available region. Alibaba Cloud CLI uses the specified region ID to initiate API calls. For more information about the available regions, see Endpoints.
NoteWhen you use Alibaba Cloud CLI, you can use the
--regionoption to specify a region for a single command. This option overrides the region setting in your default credential configuration and environment variables. For more information, see Command options. -
Use the RAM user's AccessKey pair to configure AccessKey-based credentials. Name the configuration profile
AkProfile. For more information, see Configure and manage identity credentials.
Generate a CLI command
-
Log on to the API debugging page for ENS.
-
On the API debugging page, use the left-side search box to find the API you want to use. In the Parameter Configuration section, fill in the required parameters. Then, click the CLI Example tab next to the Parameter Configuration section to generate a command example.
-
Click the
icon. You are directed to Cloud Shell. You can debug the command in Cloud Shell. -
Click the
icon to copy the CLI command to the clipboard and paste the command to the local shell. -
When you paste the sample command into your shell for debugging, take note of the formats of parameters. For more information about the parameter formats of Alibaba Cloud CLI, see Parameter formats.
-
The example generated by OpenAPI Explorer includes the
--regionoption by default. When you run the command locally, Alibaba Cloud CLI prioritizes this option, ignoring the region settings in your default credential configuration and environment variables. You can remove or keep this option as needed.
-
-
Call an API operation
Syntax
Alibaba Cloud CLI uses the following command syntax. For more information, see Syntax.
aliyun <command> <subcommand> [options and parameters]
Command options
You can specify command options to change command behavior or enable extended features. Common options include:
-
--profile <profileName>: When you use the--profileoption and specify a valid configuration nameprofileName, Alibaba Cloud CLI ignores the default identity credential configuration and environment variables, and prioritizes the specified configuration to invoke the command. -
--help: At any command level, use the--helpoption to get help for that command. For more information, see Get help information.
For more information, see Command line options for API calls.
Call example
The following example calls the RebootInstance command in ENS to restart an instance. For more information about the RebootInstance command, see RebootInstance.
-
Run the following command:
aliyun ens RebootInstance --InstanceId i-5xxx8d3x --endpoint ens.aliyuncs.com -
View the command output.
{ "Code": "0", "RequestId": "845748BB-9E66-52DB-B4F5-4305601AD2CF" }
If an error is returned after you call an API operation of ENS, check whether the input parameters and values are valid based on the error code.
You can also record the request ID from the response or the SDK error message and use Alibaba Cloud OpenAPI Diagnostics to diagnose the issue.