All Products
Search
Document Center

:Integrate CLI with Private DNS

Last Updated:Sep 10, 2024

Alibaba Cloud Command Line Interface (CLI) is a general-purpose command-line tool that is developed based on OpenAPI Explorer. You can integrate Alibaba Cloud CLI with Private DNS and manage the resources of Private DNS by using a shell tool. This topic describes how to use Alibaba Cloud CLI to call the API operations of Private DNS.

Background information

For more information about Alibaba Cloud CLI, see What is Alibaba Cloud CLI?

Install Alibaba Cloud CLI

You must install Alibaba Cloud CLI before you can use Alibaba Cloud CLI. You can install Alibaba Cloud CLI on the 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 provided by Alibaba Cloud to debug the commands that you want to run in Alibaba Cloud CLI. For more information about Cloud Shell, see What is Cloud Shell?

Configure Alibaba Cloud CLI

Important

An Alibaba Cloud account has the 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 and use a RAM user to call API operations or perform routine O&M operations. You must attach the AliyunPvtzFullAccess policy to the RAM user. This policy allows the RAM user to manage the resources of Private DNS.

Before you use Alibaba Cloud CLI, you must configure information such as identity credentials and a region ID in Alibaba Cloud CLI. Alibaba Cloud CLI supports various identity credentials. For more information, see the Credential types section of the Configure profiles topic. In this example, AccessKey credentials are used. Perform the following steps to configure Alibaba Cloud CLI:

  1. Create a RAM user and grant the permissions to manage Alibaba Cloud services based on your business requirements. For more information, see Create a RAM user and Grant permissions to a RAM user.

  2. Create an AccessKey pair for the RAM user and record the AccessKey ID and AccessKey secret for the subsequent configuration of identity credentials. For more information, see Create an AccessKey pair.

  3. Specify a region ID. Alibaba Cloud CLI calls API operations in the specified region. For more information about available regions, see Endpoints.

    Note

    When you use Alibaba Cloud CLI, you can specify the --region option to run a command in a specific region. If you specify this 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 identity credentials topic.

Generate a CLI command

  1. Go to the Debugging page of the Private DNS API.

  2. In the left-side search box of the Debugging page, search for the API operation that you want to call. On the Parameters tab of the API operation, specify the parameters based on the API reference. Click the CLI Example tab on the right side to view the generated sample command that contains the specified parameters.

    image

    • Click the Run Command in CloudShellimage icon to start Cloud Shell and debug the command in Cloud Shell.

    • Click the Copyimage icon to copy the sample command to the clipboard. You can paste the sample command into your local shell tool to run the sample command.

      • Pay attention to the parameter formats when you copy and paste the CLI command to the local shell tool. For more information about the parameter formats in Alibaba Cloud CLI commands, see Parameter formats.

      • By default, the --region option is added to the sample command that is generated in OpenAPI Explorer. When you copy the command to your local shell tool, Alibaba Cloud CLI ignores the region information in the default credential configurations and environment variable settings, and preferentially runs the command in the specified region. You can delete or retain this option based on your business requirements.

Use Alibaba Cloud CLI to call the API operations of Private DNS

Syntax

In Alibaba Cloud CLI, you can use the syntax shown in the following code block to run commands. For more information, see Syntax.

aliyun <command> <subcommand> [options and parameters]

Command options

When you use Alibaba Cloud CLI, you can specify command options to change the default behaviors of commands or implement the extended features of commands. The following command options are frequently used:

  • --profile<profileName>: You can use the --profile option and the profileName parameter to specify a configuration profile. After you specify a valid configuration profile, Alibaba Cloud CLI ignores the information in default credential configurations and environment variable settings and preferentially uses the configurations that you specify to run commands.

  • --help: You can specify the --help option to obtain the help information about a command. For more information, see Use the help command.

For more information, see Command line options for API calls.

Examples

Note

In the following examples, commands are run in Command Prompt of Windows. The parameter formats of commands vary on other operating systems. For more information about the parameter formats in Alibaba Cloud CLI commands, see Parameter formats.

  • Example 1: Use Alibaba Cloud CLI to call the AddZone operation of Private DNS to create a zone named zone_test in the built-in authoritative acceleration module.

    1. Run the command.

      aliyun pvtz AddZone --region cn-qingdao --ZoneName zone_test --DnsGroup FAST_ZONE
    2. View the command output.

      {
              "RequestId": "139C297E-8E9C-5E06-8758-CD4D6A4C89AF",
              "Success": true,
              "ZoneId": "79e6d8c6974042e9c9a4a988130****",
              "ZoneName": "zone_test"
      }
  • Example 2: Use Alibaba Cloud CLI to call the AddZoneRecord operation of Private DNS to add a Domain Name System (DNS) record for the zone named zone_test.

    1. Run the command.

      aliyun pvtz AddZoneRecord --region cn-qingdao --ZoneId 79e6d8c6974042e9c9a4a9881306**** --Rr www --Type A --Value '192.168.XX.XX'
    2. View the command output.

      {
              "RecordId": 440563****,
              "RequestId": "61DD3A77-9E25-5E86-A314-3E2B741BE44A",
              "Success": true
      }
  • Example 3: Use Alibaba Cloud CLI to call the BindZoneVpc operation of Private DNS. This API operation is used to associate one or more virtual private clouds (VPCs) with the zone named zone_test to specify the effective scope of the zone.

    1. Run the command.

      aliyun pvtz BindZoneVpc --region cn-qingdao --ZoneId 79e6d8c6974042e9c9a4a9881306**** --Vpcs.1.VpcId 'vpc-0jl96awrjt75ezglc****'
    2. View the command output.

      {
              "RequestId": "9D48AF1B-A5DE-50B8-9882-481C8C5010F8"
      }
Note

If an error code is returned after you call an API operation of Private DNS, you must check whether the request parameters and their values are valid based on the returned error code.

You can also use Alibaba Cloud OpenAPI Diagnostics to perform self-service diagnostics based on the returned request ID or SDK error information.