Call AnalyticDB for PostgreSQL OpenAPI operations by using Alibaba Cloud CLI
This topic uses the DescribeDBClusterNode operation, which queries the node information of an instance, as an example to describe the procedure of calling AnalyticDB for PostgreSQL OpenAPI operations by using Alibaba Cloud CLI.
Prerequisites
Alibaba Cloud Command Line Interface (CLI) is a general-purpose command-line tool built on OpenAPI. 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 use Alibaba Cloud CLI, you must install it. Alibaba Cloud CLI supports Windows, Linux, and macOS. Select the installation service that matches the operating system of your device.
Windows: Install the CLI on Windows.
Linux: Install the CLI on Linux.
macOS: Install the CLI on macOS.
You can also debug Alibaba Cloud CLI commands in Cloud Shell. Alibaba Cloud CLI is pre-installed in Cloud Shell, and the software version is updated regularly. For more information, see What is Cloud Shell?.
Step 2: Configure Alibaba Cloud CLI
An Alibaba Cloud account has the permissions to manage and access all product OpenAPI operations, which poses high security risks. We strongly recommend that you create a RAM identity, grant permissions to the RAM identity based on the principle of least privilege, and use the RAM identity to access OpenAPI operations. For more information about the permission policies supported by AnalyticDB for PostgreSQL, see RAM policies and System policies.
Before you use Alibaba Cloud CLI, you must configure identity credentials, region IDs, and other information in Alibaba Cloud CLI. Alibaba Cloud CLI supports multiple types of identity credentials. For more information, see Credential types. This topic uses AccessKey credentials as an example. The procedure is as follows:
Create a RAM user and an AccessKey for subsequent identity credential configuration. For more information, see Create a RAM user and Create an AccessKey.
Grant permissions to the RAM user. This example requires the read-only permission
AliyunGPDBReadOnlyAccesson AnalyticDB for PostgreSQL. For more information, see Grant permissions to a RAM user.Obtain the available region IDs for subsequent identity credential configuration. Alibaba Cloud CLI uses the specified region to initiate OpenAPI calls. For the available regions of AnalyticDB for PostgreSQL, see Regions and endpoints.
NoteWhen you use Alibaba Cloud CLI, you can use the
--regionoption to specify the region for a command call. This option takes precedence over the region information in the default identity credential configuration and environment variables. For more information, see Command-line options.Use the AccessKey of the RAM user to configure AccessKey credentials and name the profile
AkProfile. For more information, see Configuration examples.
Step 3: Generate a CLI command example
In the OpenAPI Portal, access the DescribeDBClusterNode debugging page.
In the Parameter Configuration area, enter the request parameters, and click the CLI Example tab to view the generated CLI example.
Copy the CLI example or quickly run it in Cloud Shell:
Click Run Command
to open Cloud Shell and quickly debug the command.Click Copy
to copy the CLI example to the clipboard. You can paste it into a local shell tool to run or use it to edit automated command-line scripts.
NoteWhen you copy the CLI example to a local shell tool for debugging, pay attention to the parameter format. For more information about the parameter format of Alibaba Cloud CLI commands, see Parameter formats.
The example generated on the OpenAPI Portal includes the
--regionoption by default. When you copy the command to a local environment, Alibaba Cloud CLI ignores the region information in the default identity credential configuration and environment variables, and uses the region specified in the command. You can delete or retain this option as needed.
Step 4: Call AnalyticDB for PostgreSQL OpenAPI operations
Example 1: List the AnalyticDB for PostgreSQL OpenAPI operations that can be called by using Alibaba Cloud CLI
The following example shows how to use the --help option to list the AnalyticDB for PostgreSQL OpenAPI operations that can be called by using Alibaba Cloud CLI. For more information, see Get help information.
Run the command.
aliyun gpdb --helpThe following output is returned.
Product: gpdb (AnalyticDB for PostgreSQL) Version: 2016-05-03 Available Api List: AllocateInstancePublicConnection BindDBResourceGroupWithRole CancelUploadDocumentJob CancelUpsertCollectionDataJob CheckHadoopDataSource CheckHadoopNetConnection CheckJDBCSourceNetConnection CheckServiceLinkedRole CreateAccount CreateCollection CreateDBInstance
Example 2: Queryinstance node information
The following example shows how to use Alibaba Cloud CLI to call theDescribeDBClusterNodeoperation to obtain theMasternode information of the specified instance by using the instance ID.
Run the command.
aliyun gpdb DescribeDBClusterNode --DBInstanceId 'gp-bp13ue79qk8y1****' --NodeType masterThe following output is returned.
{ "Nodes": [ { "Name": "master-10*******" } ], "RequestId": "87E44B48-B306-4AD3-A63B-C8**********", "DBClusterId": "gp-bp13ue79qk8y1****" }NoteIf an error is returned after you call an AnalyticDB for PostgreSQL OpenAPI operation, check whether the request parameters and their values are correct based on the returned error code.
You can also record the RequestId or SDK error information returned by the call, and perform self-diagnosis on the Alibaba Cloud OpenAPI Diagnostics platform .