This topic shows how to use the Alibaba Cloud CLI to call operations for PolarDB for MySQL/PostgreSQL. It uses the DescribeClassList operation as an example to demonstrate how to view available PolarDB cluster specifications.
Prerequisites
-
Before you begin, understand what Alibaba Cloud CLI is.
-
You cannot use the Alibaba Cloud CLI to call the OpenAPI of PolarDB for Xscale 2.0 (2020 version).
Step 1: Install the Alibaba Cloud CLI
To use the Alibaba Cloud CLI, you must first install it. The Alibaba Cloud CLI can be installed on Windows, Linux, and macOS. Select the installation method for your operating system.
-
Windows: Install the CLI (Windows).
-
macOS: Install the CLI (macOS).
You can also debug Alibaba Cloud CLI commands in Cloud Shell. Cloud Shell comes pre-installed with the Alibaba Cloud CLI and automatically configures your credentials, so you do not need to perform this step. For more information, see What is Cloud Shell?.
Step 2: Configure the Alibaba Cloud CLI
A primary account has full management and access permissions for all product OpenAPI operations, posing a high security risk. We strongly recommend creating a RAM identity, granting permissions based on the principle of least privilege, and using the RAM identity to access OpenAPI operations. For information about the permission policies supported by PolarDB for MySQL/PostgreSQL, see System permission policy reference for PolarDB and Custom permission policy reference for PolarDB.
Before you use the Alibaba Cloud CLI, you must configure your credentials, a region ID, and other information. The Alibaba Cloud CLI supports multiple types of credentials. For more information, see Configure and manage credentials. This topic uses an AccessKey pair as an example. The following steps describe the procedure:
-
Create a RAM user and an AccessKey pair to use for configuring your credentials. For more information, see Create a RAM user and Create an AccessKey.
-
Grant permissions to the RAM user. For the example in this topic, you must grant the
AliyunPolardbReadOnlyAccesspermission policy to the RAM user. This policy provides read-only access to PolarDB for MySQL/PostgreSQL. For more information, see Manage permissions for a RAM user. -
Obtain an available region ID to use for configuring your credentials. The Alibaba Cloud CLI sends OpenAPI requests to the region that you specify. For a list of available regions for PolarDB for MySQL/PostgreSQL, see service endpoints.
NoteWhen you use the Alibaba Cloud CLI, you can add the
--regionoption to specify a region for the command. This option overrides the region settings in your default credentials and environment variables. For more information, see Command-line options. -
Use the RAM user's AccessKey pair and a region ID to configure the credentials. Name the configuration profile
AkProfile. For more information, see Configure and manage credentials.
Step 3: Generate a CLI command example
-
In OpenAPI Explorer, go to the DescribeClassList debugging page.
On the Parameters tab, specify the parameters as needed. The CommodityCode parameter is required. Then, click the CLI Example tab to view the generated CLI command, for example,
aliyun polardb DescribeClassList --region cn-hangzhou. Click the copy icon to the right of the command to copy it. -
On the Parameters tab, enter the request parameters, and then click the CLI Example tab to view the generated CLI example.
-
Copy the CLI example or run it in Cloud Shell:
-
Click the Run Command
button to open Cloud Shell and run the command. -
Click the Copy
button to copy the CLI example to your clipboard. You can then paste it into your local shell to run it.
NoteIf you copy the CLI example to your local shell for debugging, make sure that the parameter format is correct. For more information about the parameter formats for Alibaba Cloud CLI commands, see Parameter formats.
The examples generated in OpenAPI Explorer include the
--regionoption by default. When you copy the command to your local environment to run it, the Alibaba Cloud CLI ignores the region information in your default credentials and environment variables, and instead uses the region specified in the command. You can remove or keep this option as needed. -
Step 4: Call PolarDB for MySQL/PostgreSQL OpenAPI
Example 1: OpenAPI operations for PolarDB for MySQL/PostgreSQL
This example shows how to use the --help option to get a list of callable OpenAPI operations for PolarDB for MySQL/PostgreSQL. For more information, see API reference.
-
Run the command.
aliyun polardb --help -
View the output.
Product: polardb (PolarDB) Version: 2017-08-01 Available Api List: CancelScheduleTasks Cancels a scheduled task that has not yet started. CheckAccountName Checks whether an account name is valid or if an account with the same name already exists in the current cluster. CheckDBName Checks whether a database name is valid or if a database with the same name already exists in the current cluster. CheckKMSAuthorized Queries the activation status of KMS. CheckServiceLinkedRole Calls the CheckServiceLinkedRole operation to check whether a service-linked role has been created. CloseAITask Disables the PolarDB for AI feature. CloseDBClusterMigration Cancels or completes a one-click migration task from RDS to PolarDB. CreateAccount Creates a PolarDB database account.
Example 2: Get cluster specifications
This example shows how to call the DescribeClassList operation to query available subscription cluster specifications for PolarDB for MySQL/PostgreSQL in the Chinese mainland.
-
If you use an Alibaba Cloud account on the China site, you can view only the commodity codes for the Chinese mainland.
-
If you use an Alibaba Cloud account on an international site, you can view only the commodity codes for regions outside the Chinese mainland.
-
If you use a Jushita account, you can view only Jushita commodity codes.
-
If you use a Cainiao account, you can view only Cainiao commodity codes.
-
Run the command.
aliyun polardb DescribeClassList --CommodityCode polardb_sub -
View the output.
{ "RequestId": "69A85BAF-1089-4CDF-A82F-0A140F******", "Items": [ { "Psl4MaxIOPS": "48000", "ClassTypeLevel": "enterprise", "Cpu": "8", "ReferencePrice": "200000", "ReferenceExtPrice": "200000", "MaxConnections": "8000", "MemoryClass": "32", "ClassCode": "polar.mysql.x4.medium", "ClassGroup": "Exclusive package", "Psl5MaxIOPS": "96000", "MaxIOPS": "32000", "MaxStorageCapacity": "20", "Pl1MaxIOPS": "50000", "Pl2MaxIOPS": "100000", "Pl3MaxIOPS": "1000000" } ], "RegionId": "cn-hangzhou" }NoteIf a PolarDB for MySQL/PostgreSQL OpenAPI call returns an error, use the error code to check if your request parameters and values are valid.
Alternatively, record the RequestID or the SDK's error message and use OpenAPI Explorer to run a self-service diagnosis.