This topic describes how to use Alibaba Cloud CLI to call the API operations of AnalyticDB for PostgreSQL. In this example, the DescribeDBClusterNode operation is used.
Before you begin
Alibaba Cloud CLI is a universal command-line tool that is developed based on APIs. You can use Alibaba Cloud CLI to automate the management and maintenance of AnalyticDB for PostgreSQL. For more information, see What is Alibaba Cloud CLI?
Step 1: Install Alibaba Cloud CLI
Before you can use Alibaba Cloud CLI, you must install Alibaba Cloud CLI. You can install Alibaba Cloud CLI on Windows, Linux, and macOS operating systems. Select an installation package of Alibaba Cloud CLI based on the operating system of your device. For more information, see the following topics:
You can also use Cloud Shell to debug the commands that you want to run in Alibaba Cloud CLI. Alibaba Cloud CLI is built into Cloud Shell, which regularly updates the software version. For more information, see What is Cloud Shell?
Step 2: Configure Alibaba Cloud CLI
An Alibaba Cloud account has permissions to manage and access the APIs of all Alibaba Cloud services. If you use an Alibaba Cloud account to call API operations, security risks may arise. We recommend that you create a Resource Access Management (RAM) identity, grant the required permissions to the RAM identity based on the principle of least privilege, and then use the RAM identity to call API operations. For information about the policies supported by AnalyticDB for PostgreSQL, see System policies for GPDB and AnalyticDB for PostgreSQL custom policies.
Before you use Alibaba Cloud CLI, you must specify information, such as identity credentials and a region ID, in Alibaba Cloud CLI. Alibaba Cloud CLI supports various types of identity credentials. For more information, see the "Credential types" section of the Configure profiles topic. In this example, AccessKey credentials are used. To use AccessKey credentials, perform the following steps:
Create a RAM user and create an AccessKey pair for the RAM user. For more information, see Create a RAM user and Create an AccessKey pair.
Grant the required permissions to the RAM user. In this example, attach the
AliyunGPDBReadOnlyAccesspolicy to the RAM user to grant the RAM user the read-only permissions on AnalyticDB for PostgreSQL. For more information, see Grant permissions to a RAM user.Obtain the ID of the region that you want to use to configure identity credentials. Alibaba Cloud CLI uses the region ID that you specify to initiate API calls. For information about regions in which AnalyticDB for PostgreSQL is available, see Endpoints.
NoteWhen you use Alibaba Cloud CLI, you can use the
--regionoption to run a command in a specific region. If you use the option, Alibaba Cloud CLI ignores the region information in the default credential configurations and environment variable settings. For more information, see Command line options for API calls.Use the AccessKey pair of the RAM user to configure identity credentials in the configuration file named
AkProfile. For more information, see the "Configuration examples" section of the Configure profiles topic.
Step 3: Generate a CLI command
In OpenAPI Explorer, call the DescribeDBClusterNode operation.

On the Parameters tab, configure the parameters. Then, click the CLI Example tab to view the generated sample CLI command.
Copy the CLI command or debug the CLI command in Cloud Shell.
Click the
icon to start Cloud Shell and debug the CLI command in Cloud Shell. Click the
icon to copy the CLI command to the clipboard and paste the command to the local shell for running or editing the automation CLI script.
NoteWhen you paste the CLI command to your shell for debugging, take note of the formats of parameters. For information about the parameter formats of Alibaba Cloud CLI, see Parameter formats.
By default, OpenAPI Explorer adds the
--regionoption to the generated CLI command. When you paste the command to your shell, Alibaba Cloud CLI ignores the region information in the default identity credential configurations and environment variable settings, and preferentially runs the command in the specified region. You can delete or retain the option based on your business requirements.
Step 4: Call API operations of AnalyticDB for PostgreSQL
Example 1: Query the API operations of AnalyticDB for PostgreSQL supported by Alibaba Cloud CLI
The following example shows how to use the --help option to query the API operations of AnalyticDB for PostgreSQL supported by Alibaba Cloud CLI. For more information, see List of operations by function.
Run the following command:
aliyun gpdb --helpView the command output.

Example 2: Query information about instance nodes
The following example shows how to call the DescribeDBClusterNode operation of AnalyticDB for PostgreSQL to query information about the coordinator node of an instance by using Alibaba Cloud CLI.
Run the following command:
aliyun gpdb DescribeDBClusterNode --DBInstanceId 'gp-bp13ue79qk8y1****' --NodeType masterView the command output.
{ "Nodes": [ { "Name": "master-10*******" } ], "RequestId": "87E44B48-B306-4AD3-A63B-C8**********", "DBClusterId": "gp-bp13ue79qk8y1****" }NoteIf an error is returned after you call an API operation of AnalyticDB for PostgreSQL, check whether the request parameters and values are valid based on the error code.
You can also perform self-service diagnostics based on the returned request ID or SDK error message on the OpenAPI problem diagnosis page.