CLI integration example
Alibaba Cloud CLI is a general-purpose command-line tool built on OpenAPI that you can use to automate the management and maintenance of AnalyticDB for MySQL. This topic describes the steps and provides examples of how to use Alibaba Cloud CLI to manage AnalyticDB for MySQL.
Prerequisites
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 provides installation packages for Windows, Linux, and macOS. Select the installation method for your operating system.
-
Windows: Install Alibaba Cloud CLI on Windows.
You can also use Cloud Shell to debug Alibaba Cloud CLI commands. For more information about Cloud Shell, see What is Cloud Shell?.
Configure Alibaba Cloud CLI
An Alibaba Cloud account has full permissions to manage all API operations, which poses a high security risk.
Before you use Alibaba Cloud CLI, you must configure your identity credentials, region ID, and other information. Alibaba Cloud CLI supports multiple types of identity credentials. For more information, see Configure profiles. This topic uses AccessKey credentials as an example. Follow these steps:
-
Create a RAM user and grant the required permissions. For more information, see Create a RAM user and Manage RAM user permissions.
ImportantFor this example, you must attach the
AliyunADBFullAccesspolicy to the RAM user. In practice, grant permissions as needed before you call API operations. For more information about the policies for AnalyticDB for MySQL, see System policy reference for AnalyticDB for MySQL. -
After creating and authorizing the RAM user, create an AccessKey pair for the user. Record the
AccessKey IDandAccessKey Secretto configure your identity credentials. For more information, see Create an AccessKey. -
Obtain and record an available region ID. Alibaba Cloud CLI sends API requests to the region that you specify. For information about the regions where Enterprise Edition, Basic Edition, or Data Lakehouse Edition is available, see Endpoints.
NoteWhen you use Alibaba Cloud CLI, you can add the
--regionoption to a command to specify a region for the request. This option overrides the region settings in your default profile and environment variables. For more information, see Command-line options. -
Use the AccessKey pair of the RAM user to configure AK credentials. Name the profile
AkProfile. For more information, see Configure profiles.
Generate a CLI command example
-
Go to the Enterprise Edition, Basic Edition, or Data Lakehouse Edition API Debugging page.
-
On the API Debugging page, you can search for the API that you want to use in the search box on the left. In the Parameters section, specify parameters based on the API documentation, and click the CLI Sample tab to the right of Parameters to generate a command sample that includes the specified parameters. In the left-side navigation pane, search for and select the target API (for example, DescribeDBClusterAttribute under Cluster Management). In the Parameter Configuration section, set required parameters such as Version (for example,
2021-12-01), Service Endpoint (for example, China (Hangzhou)), and DBClusterId. Then, click the CLI Sample tab on the right to view the generated CLI command, for example:aliyun adb DescribeDBClusterAttribute --region cn-hangzhou --version 2021-12-01 --method POST --force.-
Click the
icon to open Cloud Shell and quickly debug the command. -
Click the
icon to copy the CLI example to your clipboard. You can then paste it into your local shell to run it.-
When you paste the command example into a local shell for debugging, ensure the parameter format is correct. For more information about the parameter formats for Alibaba Cloud CLI commands, see Parameter formats.
-
By default, examples generated in OpenAPI Portal include the
--regionoption. When you copy the command to run it locally, Alibaba Cloud CLI ignores the region settings in your default profile and environment variables, and prioritizes the region specified in the command. You can remove or keep this option as needed.
-
-
Call an API
Command syntax
Alibaba Cloud CLI uses the following general command syntax. For more information, see Generate and run CLI commands.
aliyun <command> <subcommand> [options and parameters]
Command-line options
In Alibaba Cloud CLI, you can use command-line options to modify the default behavior of a command or provide additional functionality. Common options include:
-
--profile <profileName>: If you use the--profileoption and specify a valid profile nameprofileName, Alibaba Cloud CLI ignores the default credential configuration and environment variable settings, and uses the specified profile to run the command. -
--help: Enter the--helpoption at the command level where you need help to get the help information for that 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 a specified Enterprise Edition, Basic Edition, or Data Lakehouse Edition cluster. For more information about the DescribeDBClusterAttribute operation, see DescribeDBClusterAttribute.
-
Run the command.
aliyun adb DescribeDBClusterAttribute --region cn-hangzhou --DBClusterId 'amv-bp15yg4o68****' --version 2021-12-01 --method POST --force -
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****" }