Alibaba Cloud CLI integration example
Alibaba Cloud CLI is a general-purpose command-line tool developed based on APIs. Use it to manage RDS instances from your shell instead of the console.
Prerequisites
Before you begin, ensure that you have:
-
An Alibaba Cloud account with access to ApsaraDB RDS
-
A RAM user with the AliyunRDSReadOnlyAccess or AliyunRDSFullAccess policy attached
NoteFor more information about ApsaraDB RDS access policies, see Use RAM for access control.
-
An AccessKey pair (AccessKey ID and AccessKey secret) for that RAM user
-
A region ID for the region where your RDS instance resides — see Endpoints
Using root account credentials to call API operations poses security risks. Create a dedicated RAM user for API access. See Create a RAM user and Grant permissions to a RAM user.
Install Alibaba Cloud CLI
Install Alibaba Cloud CLI for your operating system:
-
Windows: Install Alibaba Cloud CLI on Windows
Alternatively, use Cloud Shell to run Alibaba Cloud CLI commands in your browser without a local installation. See What is Cloud Shell?
Configure Alibaba Cloud CLI
Alibaba Cloud CLI supports several credential types. For most use cases, start with AccessKey credentials.
| Credential type | When to use | Instructions |
|---|---|---|
| AccessKey (long-term) | Service accounts and automation scripts | Steps below |
| Other credential types | Short-term or federated access | Credential types |
To configure AccessKey credentials:
-
Create an AccessKey pair for your RAM user and record the AccessKey ID and AccessKey secret. See Create an AccessKey pair for a RAM user.
-
Use the AccessKey pair to configure identity credentials in the
AkProfileconfiguration profile. For more information, see Configuration example. -
(Optional) To run a command in a specific region without changing your default profile, append
--region <region-id>to any command. This overrides the region in both the default profile and environment variables. See Command-line options.
Generate a CLI command
Use OpenAPI Explorer to build CLI commands interactively:
-
Go to the page of the ApsaraDB RDS API.
-
In the left-side search box, search for the API operation you want to call.
-
On the Parameters tab, fill in the parameter values.
-
Click the CLI Example tab to see the generated command with your parameters pre-filled. From the CLI Example tab:
-
Click
to copy the command to your clipboard. -
Click
to open Cloud Shell and run the command in your browser.

-
OpenAPI Explorer adds --region to generated commands by default. When present, this option overrides your default profile and environment variable settings. Remove or keep it based on your workflow. For parameter formatting requirements, see Parameter formats.
Call ApsaraDB RDS API operations
Command syntax
All Alibaba Cloud CLI commands follow this structure. See Command structure for details.
aliyun <command> <subcommand> [options and parameters]
Common command options
| Option | Description |
|---|---|
--profile <profileName> |
Use the specified configuration profile. Overrides the default credential configuration and environment variables. |
--region <regionId> |
Run the command in the specified region. Overrides the default credential configuration and environment variables. |
--help |
Print help information for a command. See Use the help command. |
For all available options, see Command-line options.
Example 2: Query instance details
The following command calls DescribeDBInstanceAttribute to retrieve the full configuration of an RDS instance:
aliyun rds DescribeDBInstanceAttribute --region cn-hangzhou --DBInstanceId 'pgm-bp16k272p478****'
| Parameter | Description | Example |
|---|---|---|
--region |
The region where the instance resides | cn-hangzhou |
--DBInstanceId |
The ID of the RDS instance to query | pgm-bp16k272p478**** |
Output:
{
"Items": {
"DBInstanceAttribute": [
{
"AccountMaxQuantity": 99999,
"AccountType": "Mix",
"AdvancedFeatures": "LinkedServer,DistributeTransaction",
"AutoUpgradeMinorVersion": "Auto",
"AvailabilityValue": "100.0%",
"BabelfishConfig": {},
"CanTempUpgrade": false,
"Category": "HighAvailability",
"ColdDataEnabled": false,
"ConnectionMode": "Standard",
"ConnectionString": "pgm-bp16k272p478****.pg.rds.aliyuncs.com",
"ConsoleVersion": "2",
"CreationTime": "2024-08-06T06:18:48Z",
"CurrentKernelVersion": "rds_postgres_1400_20240530",
"DBClusterNodes": {
"DBClusterNode": []
},
"DBInstanceCPU": "2",
"DBInstanceClass": "pg.n4.2c.2m",
"DBInstanceClassType": "x",
"DBInstanceDescription": "DB-test",
"DBInstanceDiskUsed": 3520069632,
"DBInstanceId": "pgm-bp16k272p478****",
"DBInstanceMemory": 8192,
"DBInstanceNetType": "Intranet",
"DBInstanceStatus": "Running",
"DBInstanceStorage": 100,
"DBInstanceStorageType": "cloud_essd",
"DBInstanceType": "Primary",
"DBMaxQuantity": 99999,
"DedicatedHostGroupId": "",
"DeletionProtection": false,
"DispenseMode": "MultiAVZDispenseMode",
"Engine": "PostgreSQL",
"EngineVersion": "14.0",
"ExpireTime": "",
"Extra": {
"DBInstanceIds": {
"DBInstanceId": []
}
},
"IPType": "IPv4",
"InsId": 1,
"InstanceNetworkType": "VPC",
"InstructionSetArch": "x86",
"IoAccelerationEnabled": "0",
"LatestKernelVersion": "rds_postgres_1400_20240530",
"LockMode": "Unlock",
"MaintainTime": "18:00Z-22:00Z",
"MasterZone": "cn-hangzhou-j",
"MaxConnections": 800,
"MaxIOMBPS": 0,
"MaxIOPS": 6800,
"OriginConfiguration": "{\"KindCode\":\"18\"}",
"PayType": "Postpaid",
"Port": "5432",
"ProxyType": 2,
"ReadOnlyDBInstanceIds": {
"ReadOnlyDBInstanceId": []
},
"RegionId": "cn-hangzhou",
"ResourceGroupId": "rg-acfmz7u4zzrngoa",
"SecurityIPList": "0.0.0.0/0,172.16.0.0/12",
"SecurityIPMode": "normal",
"ServerlessConfig": {},
"SlaveZones": {
"SlaveZone": [
{
"ZoneId": "cn-hangzhou-k"
}
]
},
"SuperPermissionMode": "",
"SupportCreateSuperAccount": "Yes",
"SupportUpgradeAccountType": "Yes",
"Tips": "ok",
"TipsLevel": 1,
"VSwitchId": "vsw-bp1sxxsodv28ey5dl****",
"VpcCloudInstanceId": "pgm-bp16k272p478****-20240806141842",
"VpcId": "vpc-bp1ov7as4yvz4kxei****",
"ZoneId": "cn-hangzhou-j",
"kindCode": "18"
}
]
},
"RequestId": "14B99E32-4ECD-5B8E-A9C8-6738C8C95910"
}
Troubleshooting
If an API call returns an error, check that the parameter names and values match the API reference for that operation.
For self-service diagnostics, go to Alibaba Cloud OpenAPI Diagnostics and enter the RequestId from the error response.
What's next
-
What is Alibaba Cloud CLI? — full feature overview
-
Parameter formats — how to pass complex parameter types (JSON arrays, structs)
-
Command-line options — all supported flags and their precedence rules