All Products
Search
Document Center

CDN:Use CLI to manage Alibaba Cloud CDN resources

Last Updated:Sep 13, 2024

Alibaba Cloud CLI is a general-purpose command-line tool that is developed based on OpenAPI. You can use Alibaba Cloud CLI to implement automatic management and maintenance of Alibaba Cloud CDN resources. This topic describes how to use Alibaba Cloud CLI to call Alibaba Cloud CDN API operations.

Before you begin

Get yourself familiar with Alibaba Cloud CLI. For more information, 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 in the Windows, Linux, and macOS operating systems. You must 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 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 Resource Access Management (RAM) user to call API operations or perform routine O&M operations.

Before you use Alibaba Cloud CLI, you must configure information such as identity credentials and region ID in Alibaba Cloud CLI. Alibaba Cloud CLI supports various identity credentials. For more information, see Credential types. In this example, AccessKey credentials are used.

  1. Create a RAM user and grant the RAM user the required permissions. For more information, see Create a RAM user and Grant permissions to a RAM user.

    Important

    In this example, you need to attach the AliyunCDNReadOnlyAccess policy to the RAM user. You can use the AliyunCDNFullAccess system policy, which grants the user full access to Alibaba Cloud CDN-accelerated domain names, such as querying and managing domain names. You can also create custom policies. For more information, see Alibaba Cloud CDN custom policies.

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

  3. Obtain and record the ID of an available region for the configuration of identity credentials. Alibaba Cloud CLI uses the specified region ID to initiate API calls. For more information about the available regions, see Request structure.

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

Generate a CLI command

  1. Go to the Debugging page of the Alibaba Cloud CDN API.

  2. In the left-side search box of the page that appears, search for the operation that you want to call. On the Parameters tab, enter parameter values based on the API document of the API operation. Then, click the CLI Example tab on the right side of the Parameters tab to generate an example that contains configured parameters.image

    • Click the imageicon. You are directed to Cloud Shell. You can debug the command in Cloud Shell.

    • Click the imageicon to copy the CLI command to the clipboard and paste the command to the local shell.

      • When you paste the sample command into your shell for debugging, take note of the formats of parameters. For more 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 copy 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.

Call an API operation

Syntax

In Alibaba Cloud CLI, you can use the following syntax 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 behaviors of commands or implement the extended features of commands. In most cases, the following command options are 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 use 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.

Call example

The following example shows how to use Alibaba Cloud CLI to call the DescribeUserDomains operation of Alibaba Cloud CDN to query all domain names in your account and their status. For more information about the DescribeUserDomains operation, see DescribeUserDomains.

  1. Run the following command:

    image

  2. View the command output.

    image

Note

If an error is returned after you call an API operation of Alibaba Cloud CDN, check whether the input parameters and values are valid based on the 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.