All Products
Search
Document Center

AnalyticDB:Use Alibaba Cloud CLI to call the API operations of AnalyticDB for PostgreSQL

Last Updated:Nov 21, 2024

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:

  • Windows operating system: Windows.

  • Linux operating system: Linux.

  • macOS operating system: macOS.

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

Important

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:

  1. 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.

  2. Grant the required permissions to the RAM user. In this example, attach the AliyunGPDBReadOnlyAccess policy 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.

  3. 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.

    Note

    When you use Alibaba Cloud CLI, you can use the --region option 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.

  4. 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

  1. In OpenAPI Explorer, call the DescribeDBClusterNode operation.

    image

  2. On the Parameters tab, configure the parameters. Then, click the CLI Example tab to view the generated sample CLI command.

  3. Copy the CLI command or debug the CLI command in Cloud Shell.

    • Click the image icon to start Cloud Shell and debug the CLI command in Cloud Shell.

    • Click the image 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.

    Note

    When 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 --region option 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.

  1. Run the following command:

    aliyun gpdb --help
  2. View the command output.

    image

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.

  1. Run the following command:

    aliyun gpdb DescribeDBClusterNode --DBInstanceId 'gp-bp13ue79qk8y1****' --NodeType master 
  2. View the command output.

    {
      "Nodes": [
        {
          "Name": "master-10*******"
        }
      ],
      "RequestId": "87E44B48-B306-4AD3-A63B-C8**********",
      "DBClusterId": "gp-bp13ue79qk8y1****"
    }
    Note

    If 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.