Manage SelectDB instances by using an Agent and Alibaba Cloud CLI
After you configure Alibaba Cloud CLI and install the SelectDB plug-in, you can describe what you need in natural language and let an Agent call Alibaba Cloud CLI to manage your ApsaraDB for SelectDB instances. This topic uses the creation of a Serverless instance as an example to walk you through the whole procedure.
How it works
Alibaba Cloud CLI is a command-line tool built on Alibaba Cloud OpenAPI. After you install the SelectDB plug-in, you can query, create, and delete instances from the command line.
In this topic, an Agent refers to an AI assistant that can run commands on your local machine, such as Claude Code or Codex. It runs commands based on your natural language instructions and reads the returned results. You do not need to memorize the commands or their parameters. You describe what you need in natural language, and the Agent calls Alibaba Cloud CLI to manage your instances.
Prerequisites
-
Alibaba Cloud CLI is installed. This topic uses macOS as an example. For more information about how to install the CLI, see Install, update, and uninstall Alibaba Cloud CLI.
-
Configure and manage credentials. An Alibaba Cloud account has full permissions on all resources, and leaked credentials for this account pose a significant security risk. Use the AccessKey of a RAM user instead, and grant the AliyunSelectDBFullAccess permission to that RAM user. For more information about how to grant permissions, see Manage RAM user permissions.
-
An Agent that can run commands on your local machine is ready.
Step 1: Configure Alibaba Cloud CLI
-
Run the following command to create a profile named
AkProfile.aliyun configure --profile AkProfileEnter your AccessKey ID, AccessKey Secret, and region ID as prompted. The following output indicates that the configuration is successful.
Configuring profile 'AkProfile' in 'AK' authenticate mode... Access Key Id []: <yourAccessKeyID> Access Key Secret []: <yourAccessKeySecret> Default Region Id []: cn-hangzhou Default Output Format [json]: json (Only support json) Default Language [zh|en] en: en Saving profile[AkProfile] ...Done.NoteThe output format (Default Output Format) supports only
json. -
Run the following command to install the SelectDB plug-in.
aliyun plugin install --name selectdb -
Run the following command to verify that the plug-in is installed.
aliyun selectdb --helpA list of SelectDB commands indicates that the plug-in is installed.
Step 2: Provide the required context to the Agent
Before you use the Agent to manage instances, guide it to learn the SelectDB commands from the help output. Enter the following prompt.
Alibaba Cloud CLI is installed on this machine. Run aliyun selectdb --help to learn the available management operations. You will use the CLI to manage SelectDB instances.
If you skip this context and ask the Agent to manage instances through Alibaba Cloud CLI right away, the Agent has to discover the commands by trial and error. In our tests, the Agent needed up to eight attempts before a command ran correctly, which took a long time. Guiding the Agent to learn the commands from aliyun selectdb --help first greatly reduces the number of attempts and shortens the overall time.
After the Agent runs the help command, it summarizes the SelectDB management capabilities. The following table lists the commands that are commonly used to manage instances. All of them are subcommands of aliyun selectdb.
|
Command |
Description |
|
|
Queries the instances in a specified region. |
|
|
Queries the details of a specified instance. |
|
|
Creates an instance. |
|
|
Deletes an instance. |
The preceding table lists only some of the commonly used commands. For the complete list, refer to the actual output of aliyun selectdb --help.
Step 3: Create a Serverless instance by using the Agent
-
Enter the following prompt to request a new instance.
Create a SelectDB Serverless instance for me. Confirm the parameters with me first.ImportantMake sure that your prompt asks the Agent to confirm the parameters with you. Otherwise, the Agent may set the parameters on its own and create an instance that does not meet your requirements.
-
Confirm the instance parameters one by one as prompted by the Agent. The following table lists the parameters that are confirmed in this example.
Parameter
Example value
Description
Region
cn-hangzhou
The region where the instance resides. Select the same region as the cloud servers that need to access the instance. Otherwise, the two cannot communicate over a virtual private cloud (VPC). For the supported regions, see Endpoints.
Billing method
Pay-as-you-go (Postpaid)
Pay-as-you-go (Postpaid) and subscription (Prepaid) are supported.
Database engine version
4.1
Versions 4.0 and 4.1 are supported. Use 4.1.
Instance class
selectdb.xlarge
The following classes are available:
-
selectdb.xlarge: 4 cores, 32 GB
-
selectdb.2xlarge: 8 cores, 64 GB
-
selectdb.4xlarge: 16 cores, 128 GB
A Serverless instance scales on demand, so start with a smaller class.
Instance description
selectdb-serverless-test
The description of the instance, which helps you identify and manage the instance later.
VPC and vSwitch
Queried and specified by the Agent
If you already have a VPC and a vSwitch, provide their IDs to the Agent. If you do not, ask the Agent to query the VPCs and vSwitches that are available in the current region.
-
-
After the parameters are confirmed, the Agent runs the
create-db-instancecommand to create the instance, and then returns the instance ID and the order ID. The following output is an example.Instance ID: selectdb-bp1xg08n9**** Order ID: 2940435177**** -
Query the instance state to check whether the instance is created.
Instance initialization takes several minutes. You can ask the Agent to run the
describe-db-instance-attributecommand to query the instance state. The stateACTIVATIONindicates that the instance is created.You can also log on to the Apsara for SelectDB console and view the instance state on the Instances page.
What's next
After the instance is created, you can perform the following operations. An Agent can also perform them by calling Alibaba Cloud CLI.
-
Add a cluster. An instance can contain multiple clusters. If you want to configure a separate scaling rule for each workload, add clusters to the instance. For more information, see Use ApsaraDB for SelectDB Serverless.
-
Configure an IP address whitelist. For more information, see Configure IP address whitelist.
-
Apply for a public endpoint if you want to access the instance over the Internet. For more information, see Apply for or release a public endpoint.
-
Connect to the instance. For more information, see Instance connection.