CLI integration example

Updated at:
Copy as MD

Alibaba Cloud Command Line Interface (CLI) is a general-purpose command-line tool built on OpenAPI. You can use Alibaba Cloud CLI to automate the management and maintenance of AnalyticDB for MySQL. This topic describes the procedure and examples of calling AnalyticDB for MySQL by using Alibaba Cloud CLI.

Prerequisites

Before you read this topic, if you are not familiar with Alibaba Cloud CLI, see What is Alibaba Cloud CLI?.

Install Alibaba Cloud CLI

Before you use Alibaba Cloud CLI, you must install it. Alibaba Cloud CLI supports Windows, Linux, and macOS. Select the installation service that matches the operating system of your device.

You can also use Cloud Shell provided by Alibaba Cloud to debug Alibaba Cloud CLI commands. For more information about Cloud Shell, see What is Cloud Shell?.

Configure Alibaba Cloud CLI

Important

An Alibaba Cloud account has the permissions to manage and access all product APIs, which poses high security risks. We strongly recommend that you create and use a RAM user to call APIs or perform routine O&M.

Before you use Alibaba Cloud CLI, you must configure identity credentials, region IDs, and other information in Alibaba Cloud CLI. Alibaba Cloud CLI supports multiple types of identity credentials. For more information, see Credential types. This topic uses AccessKey credentials as an example. The procedure is as follows:

  1. Create a RAM user and grant the required operation permissions to the RAM user. For more information, see Create a RAM user and Grant permissions to a RAM user.

    Important

    This example requires you to grant the AliyunADBFullAccess policy to the RAM user. In practice, grant permissions as needed based on your business before calling APIs.

  2. After you create a RAM user and grant permissions, create the AccessKey of the RAM user, and record the AccessKey ID and AccessKey Secret for subsequent identity credential configuration. For more information, see Create an AccessKey.

  3. Obtain and record the available region IDs for subsequent identity credential configuration. Alibaba Cloud CLI uses the specified region to initiate API calls. For the available regions of AnalyticDB for MySQL, see Regions and endpoints.

    Note

    When you use Alibaba Cloud CLI, you can use the --region option to specify the region for a command call. This option takes precedence over the region information in the default identity credential configuration and environment variables. For more information, see Command-line options.

  4. Use the AccessKey of the RAM user to configure AccessKey credentials and name the profile AkProfile. For more information, see Configuration examples.

Generate a CLI command example

  1. Log on to theAPI Debugpage.

  2. In the search box on the left side of the API Debugging page, search for the API operation that you want to use. On the Parameters tab, fill in the parameters based on the API documentation, and click the CLI Example tab on the right side to generate a command example with parameters. In the left-side navigation pane, search for and select the target API operation (for example, DescribeDBClusterAttribute under Cluster Management). In the parameter configuration area, set the required parameters such as Version (for example, 2021-12-01), Service Address (for example, China (Hangzhou)), and DBClusterId. Then click the CLI Example tab on the right side to view the generated CLI command. Example: aliyun adb DescribeDBClusterAttribute --region cn-hangzhou --version 2021-12-01 --method POST --force.

    • Click image to open Cloud Shell and quickly debug the command.

    • Click image to copy the CLI example to the clipboard. You can paste it into a local shell tool to run.

      • When you copy the CLI example to a local shell tool for debugging, pay attention to the parameter format. For more information about the parameter format of Alibaba Cloud CLI commands, see Parameter formats.

      • The example generated on the OpenAPI Portal includes the --region option by default. When you copy the command to a local environment, Alibaba Cloud CLI ignores the region information in the default identity credential configuration and environment variables, and uses the region specified in the command. You can delete or retain this option as needed.

Call an API

Command structure

The general command-line structure of Alibaba Cloud CLI is as follows. For more information, see Generate and call a command.

aliyun <command> <subcommand> [options and parameters]

Common options

In Alibaba Cloud CLI, you can use command-line options as needed to modify the default behavior of commands or provide additional features. The following table describes the common command-line options:

  • --profile <profileName>: after you use the --profile option and specify a valid profile name profileName, Alibaba Cloud CLI ignores the default identity credential configuration and environment variables, and uses the specified profile to call commands.

  • --help: enter the --help option at the command level where you need help to obtain the help information of the command. For more information, see Get help information.

For more information, see Command-line options.

Example

The following example shows how to use Alibaba Cloud CLI to call the DescribeDBClusterAttribute operation of AnalyticDB for MySQL to query the information of a specified AnalyticDB for MySQL cluster. For more information about the DescribeDBClusterAttribute operation, see DescribeDBClusterAttribute.

  1. Run the command.

    aliyun adb DescribeDBClusterAttribute --region cn-hangzhou --DBClusterId 'amv-bp15yg4o68****' --version 2021-12-01 --method POST --force
  2. The following output is returned.

    {
            "Items": {
                    "DBCluster": [
                            {
                                    "ClickhouseEngineCacheSize": -1,
                                    "ClickhouseEngineEnabled": false,
                                    "CommodityCode": "ads",
                                    "ComputeResource": "0ACU",
                                    "ComputeResourceTotal": "0ACU",
                                    "ConnectionString": "amv-bp15yg4o68****.ads.aliyuncs.com",
                                    "CreationTime": "2024-09-26T05:25:46Z",
                                    "DBClusterDescription": "amv-bp15yg4o68****",
                                    "DBClusterId": "amv-bp15yg4o68****",
                                    "DBClusterNetworkType": "VPC",
                                    "DBClusterStatus": "Running",
                                    "DBClusterType": "Common",
                                    "DBVersion": "5.0",
                                    "Engine": "3.2.X.X",
                                    "EngineVersion": "3.2.2.2",
                                    "ExpireTime": "",
                                    "KmsId": "",
                                    "LockMode": "Unlock",
                                    "LockReason": "",
                                    "MaintainTime": "15:00Z-16:00Z",
                                    "Mode": "flexible",
                                    "PayType": "Postpaid",
                                    "Port": "3306",
                                    "ProductForm": "IntegrationForm",
                                    "ProductVersion": "EnterpriseVersion",
                                    "RegionId": "cn-hangzhou",
                                    "ReservedACU": "0ACU",
                                    "ReservedNodeCount": 3,
                                    "ReservedNodeSize": "8ACU",
                                    "ResourceGroupId": "rg-acfmz7u4zzrngoa",
                                    "StorageResource": "24ACU",
                                    "StorageResourceTotal": "24ACU",
                                    "SupportedFeatures": {
                                            "AutoMC": true,
                                            "ClickhouseEngine": true
                                    },
                                    "UserENIStatus": false,
                                    "VPCId": "vpc-bp15lqdl91m0fdc****",
                                    "VSwitchId": "vsw-bp1k9jdi0yznq****",
                                    "ZoneId": "cn-hangzhou-k"
                            }
                    ]
            },
            "RequestId": "C42A167C-620C-5CF4-B016-663E3****"
    }