Alibaba Cloud CLI is a command-line tool built on OpenAPI that you can use to automate Cloud Monitor management and maintenance. This topic provides the steps and examples for calling Cloud Monitor through the CLI.
Prerequisites
If you are not familiar with the Alibaba Cloud CLI, see What is Alibaba Cloud CLI?.
Install the Alibaba Cloud CLI
Install the Alibaba Cloud CLI before you use it. The CLI is available for Windows, Linux, and macOS. Select the installation method for your operating system.
-
Windows: Install the CLI (Windows).
-
Linux: Install the CLI (Linux).
-
macOS: Install the CLI (macOS).
You can also use Cloud Shell to test CLI commands. For more information, see What is Cloud Shell?.
Configure the Alibaba Cloud CLI
An Alibaba Cloud account has permissions to manage and access all product APIs, which poses a high security risk. We recommend that you create and use a Resource Access Management (RAM) user for API access or daily O&M. Grant the RAM user the AliyunCloudMonitorFullAccess permission to manage Cloud Monitor.
Before you use the CLI, configure your identity credentials and region ID. The CLI supports multiple credential types. For more information, see Credential types. The following example uses AccessKey credentials:
-
Create a RAM user and grant the permissions required to manage the products. For more information, see Create a RAM user and Manage RAM user permissions.
-
After you create the RAM user and grant permissions, create an AccessKey for the user. Record the
AccessKey IDandAccessKey secret. You will need them to configure the identity credentials later. For more information, see Create an AccessKey. -
When you configure the credentials, you must also set a region ID. The CLI uses the specified region to make API calls. For a list of available regions, see Endpoints.
NoteWhen you use the CLI, you can use the
--regionoption to specify a region for a command. This option overrides the region information in the default credential configuration and environment variables. For more information, see Command-line options. -
Use the RAM user's AccessKey to configure the AccessKey credentials. For this example, name the configuration
AkProfile. For more information, see Configuration examples.
Generate CLI command examples
-
Log on to the Cloud Monitor API debugging page.
-
On the API debugging page, search for the API that you want to call in the search box on the left. On the Parameter Settings tab, enter the required parameters. Click the CLI Example tab next to the Parameter Settings tab to generate a command example with the specified parameters.

-
Click the Run Command
button to open Cloud Shell and test the command. -
Click the Copy
button to copy the CLI example to the clipboard. You can then paste the example into a local shell tool to run it.-
When you copy a CLI example to a local shell tool to test it, make sure that the parameter format is correct. For more information about the parameter format for CLI commands, see Parameter format.
-
The examples generated in OpenAPI Explorer add the
--regionoption by default. When you copy the command to run it locally, the CLI ignores the region information in the default credential configuration and environment variables, and uses the specified region instead. You can delete or keep this option as needed.
-
-
Call product APIs
Command structure
The general command structure is as follows. For more information, see Generate and call a command.
aliyun <command> <subcommand> [options and parameters]
Common command options
You can use command-line options to modify the default behavior of a command or add features. The following are common options:
-
--profile <profileName>: Specifies a configuration profile. ReplaceprofileNamewith a valid configuration name. If you use this option, the CLI ignores the default credential configuration and environment variables, and uses the specified configuration to run the command. -
--help: Displays help information for a command. You can add this option at any command level. For more information, see Obtain help information.
For more information, see Command-line options.
Call examples
Example 1: Use the --help option to list the Cloud Monitor APIs available in the CLI. You can also view the supported APIs in API overview.
-
Run the command.
aliyun cms --help -
Output.

Example 2: Use the CLI to call the CreateMonitorGroup command in Cloud Monitor to create an application group named ECS_Group.
-
Run the command.
aliyun cms CreateMonitorGroup --GroupName ECS_Group --ContactGroups ECS_Alert_Group -
Output.
{ "Code": 200, "GroupId": 238918447, "RequestId": "6512EB11-5BF6-5504-A1Ad-B4451E2E15D2", "Success": true }NoteIf an error is returned after you call a Cloud Monitor API, use the error code to verify the request parameters and their values.
You can also record the returned RequestID and SDK error message, and use the Alibaba Cloud OpenAPI Diagnostic Platform for self-service diagnosis.