CLI integration example

Updated at:

Alibaba Cloud CLI is a unified command-line tool built on OpenAPI. You can use it to manage PrivateZone resources from a shell. This topic describes how to install, configure, and use Alibaba Cloud CLI to call PrivateZone API operations.

Background

If you are new to Alibaba Cloud CLI, start with What is Alibaba Cloud CLI?.

Install Alibaba Cloud CLI

Install Alibaba Cloud CLI for your operating system:

Alternatively, use Cloud Shell to run Alibaba Cloud CLI commands in your browser. What is Cloud Shell?.

Configure Alibaba Cloud CLI

Important

Using your Alibaba Cloud account for API access poses a high security risk. We recommend that you create a RAM user for daily operations. The RAM user must have the AliyunPvtzFullAccess permission to manage PrivateZone.

Configure your identity credential and region ID before you use Alibaba Cloud CLI. Multiple credential types are supported (Configure and manage identity credentials). The following steps use an AccessKey-based credential:

  1. Create a RAM user and grant the required permissions.

  2. Create an AccessKey pair for the RAM user and record the AccessKey ID and AccessKey Secret.

  3. Specify a region ID when configuring the credential. Alibaba Cloud CLI sends API requests to the endpoint of the specified region. Endpoints.

    Note

    Add the --region option to a command to override the region in the profile and environment variables. Command options.

  4. Configure an AK-based credential with the RAM user's AccessKey pair. Name the profile AkProfile. Configure and manage identity credentials.

Generate CLI command examples

  1. Log on to the OpenAPI Explorer page for PrivateZone.

  2. Search for the target API operation in the search box on the left. On the Parameter Configuration tab, specify request parameters. Click the CLI Example tab next to the Parameter Configuration tab to generate the command.

    • Click Run Commandimage to open Cloud Shell and debug the command.

    • Click Copyimage to copy the command to your clipboard for local execution.

      • Verify the parameter format when running copied commands locally. Parameter formats.

      • OpenAPI Explorer adds the --region option to generated commands by default. This overrides the region in your profile and environment variables. Remove it if you prefer to use your configured region.

Use the CLI with PrivateZone

Command structure

Alibaba Cloud CLI commands follow this structure. Generate and call a command.

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

Common command options

Common command options:

  • --profile<profileName>: Specify a profile name profileName to use the --profile credential instead of the default configuration and environment variables.

  • --help: Add --help to view help information for a command. Get help information.

All available options are listed in Command options.

Usage examples

Note

The following examples use Windows Command Prompt syntax. Parameter formats may differ on other operating systems. Parameter formats.

  • Example 1: Call AddZone to create a zone named zone_test in the FAST_ZONE group.

    1. Run the command.

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

      {
              "RequestId": "139C297E-8E9C-5E06-8758-CD4D6A4C89AF",
              "Success": true,
              "ZoneId": "79e6d8c6974042e9c9a4a988130****",
              "ZoneName": "zone_test"
      }
  • Example 2: Call AddZoneRecord to add a DNS record to the zone_test zone.

    1. Run the command.

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

      {
              "RecordId": 440563****,
              "RequestId": "61DD3A77-9E25-5E86-A314-3E2B741BE44A",
              "Success": true
      }
  • Example 3: Call BindZoneVpc to associate a VPC with the zone_test zone.

    1. Run the command.

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

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

If an API call fails, use the returned error code to check your request parameters and their values.

Record the RequestId or error message and use the Alibaba Cloud OpenAPI Diagnostic Platform for troubleshooting.