CLI integration example
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
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:
-
Create an AccessKey pair for the RAM user and record the
AccessKey IDandAccessKey Secret. -
Specify a region ID when configuring the credential. Alibaba Cloud CLI sends API requests to the endpoint of the specified region. Endpoints.
NoteAdd the
--regionoption to a command to override the region in the profile and environment variables. Command options. -
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
-
Log on to the OpenAPI Explorer page for PrivateZone.
-
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 Command
to open Cloud Shell and debug the command. -
Click Copy
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
--regionoption 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 nameprofileNameto use the--profilecredential instead of the default configuration and environment variables. -
--help: Add--helpto view help information for a command. Get help information.
All available options are listed in Command options.
Usage examples
The following examples use Windows Command Prompt syntax. Parameter formats may differ on other operating systems. Parameter formats.
-
Example 1: Call
AddZoneto create a zone namedzone_testin theFAST_ZONEgroup.-
Run the command.
aliyun pvtz AddZone --region cn-qingdao --ZoneName zone_test --DnsGroup FAST_ZONE -
The command returns the following output.
{ "RequestId": "139C297E-8E9C-5E06-8758-CD4D6A4C89AF", "Success": true, "ZoneId": "79e6d8c6974042e9c9a4a988130****", "ZoneName": "zone_test" }
-
-
Example 2: Call
AddZoneRecordto add a DNS record to thezone_testzone.-
Run the command.
aliyun pvtz AddZoneRecord --region cn-qingdao --ZoneId 79e6d8c6974042e9c9a4a9881306**** --Rr www --Type A --Value '192.168.XX.XX' -
The command returns the following output.
{ "RecordId": 440563****, "RequestId": "61DD3A77-9E25-5E86-A314-3E2B741BE44A", "Success": true }
-
-
Example 3: Call
BindZoneVpcto associate a VPC with thezone_testzone.-
Run the command.
aliyun pvtz BindZoneVpc --region cn-qingdao --ZoneId 79e6d8c6974042e9c9a4a9881306**** --Vpcs.1.VpcId 'vpc-0jl96awrjt75ezglc****' -
The command returns the following output.
{ "RequestId": "9D48AF1B-A5DE-50B8-9882-481C8C5010F8" }
-
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.