Alibaba Cloud CLI is a unified command-line tool built on OpenAPI Explorer that lets you automate the management and maintenance of Alibaba Cloud CDN. This topic describes how to install, configure, and use Alibaba Cloud CLI to call Alibaba Cloud CDN API operations.
Prerequisites
Before you proceed, familiarize yourself with Alibaba Cloud CLI. For more information, see What is Alibaba Cloud CLI?
Install Alibaba Cloud CLI
Install Alibaba Cloud CLI for your operating system before you begin.
-
Windows: Install the CLI on Windows.
-
Linux: Install or update the CLI.
-
macOS: Install the CLI on macOS.
Alternatively, you can use Cloud Shell to debug Alibaba Cloud CLI commands without a local installation. For more information, see What is Cloud Shell?.
Configure Alibaba Cloud CLI
An Alibaba Cloud account (root account) has full administrative access to your services and resources, which presents a significant security risk. We strongly recommend that you create and use a RAM user for API access or daily O&M.
Configure your identity credentials and a region ID before you use Alibaba Cloud CLI. Alibaba Cloud CLI supports various credential types. For more information, see Configure and manage identity credentials. This topic uses AccessKey (AK) credentials as an example.
-
Create a RAM user and grant the required permissions. For more information, see Create a RAM user and Grant permissions to a RAM user.
ImportantThis example requires that you attach the
AliyunCDNReadOnlyAccesspolicy to the RAM user. You can also attach theAliyunCDNFullAccesspolicy, which grants full control to query and modify Alibaba Cloud CDN domain names, or create a custom policy. For more information, see CDN custom policy reference. -
After you create and authorize the RAM user, create an AccessKey pair. Record the
AccessKey IDandAccessKey Secret. For more information, see Create an AccessKey. -
Obtain and record an available region ID. Alibaba Cloud CLI sends API requests to the region that you specify. For a list of available regions, see Request structure.
NoteYou can use the
--regionoption to specify a region for a command. This option overrides the default region configured in your credentials and environment variables. For more information, see Command-line options. -
Use the AccessKey pair of the RAM user to configure the credentials. Name the configuration profile
AkProfile. For more information, see Endpoints.
Generate a CLI command example
-
Go to the Debugging page for the Alibaba Cloud CDN API.
-
In the left-side search box, search for the API that you want to use. On the Parameters tab, configure the parameters based on the API documentation. Click the CLI Example tab to generate a command example with your configured parameters.
-
Click the
icon to open Cloud Shell and debug the command. -
Click the
icon to copy the CLI example. Then, paste it into your local shell to run the command.-
When you paste the example into your local shell, verify the parameter format. For more information, see Understand command parameters.
-
By default, OpenAPI Explorer adds the
--regionoption to the generated example. This option overrides the default region in your credential configuration and environment variables. Remove or keep it as needed.
-
-
Call an API operation
Command structure
Alibaba Cloud CLI commands follow this structure. For more information, see Generate and call a command.
aliyun <command> <subcommand> [options and parameters]
Common command-line options
Use command-line options to modify a command's default behavior. Common options include:
-
--profile <profileName>: Specifies a credential profile to use instead of the default. When set, Alibaba Cloud CLI ignores the default credential configuration and environment variables. -
--help: Displays help information for a command. For more information, see Get help information.
For more information, see Command-line options.
Example
The following example calls the DescribeUserDomains operation to query all domain names and their statuses under your account. For more information, see DescribeUserDomains.
-
Run the command.
aliyun cdn DescribeUserDomains --DomainName mxxxio.top -
The command returns the following output.
{ "Domains": { "PageData": [ { "CdnType": "web", "Cname": "mxxx.xxxp.w.kunlunq.com", "Coverage": "domestic", "Description": "", "DomainId": 201xxx553, "DomainName": "mjlxxxao.top", "DomainStatus": "online", "GlobalResourcePlan": "off", "GmtCreated": "2024-08-27T06:29:36Z", "GmtModified": "2024-08-27T06:34:04Z", "ResourceGroupId": "rg-acfmwpdflelaoai", "Sandbox": "", "Sources": { "Source": [ { "Content": "183.xxx.xxx.88.cn-hangzhou.sae.aliyuncs.com", "Port": 80, "Priority": "20", "Type": "domain", "Weight": "10" } ] } } ] }, "PageNumber": 1, "PageSize": 20, "RequestId": "E4EBD2BF-5EB0-4044-9B97-xxxxxx", "TotalCount": 1 } } ] }, "SslProtocol": "off" } ] }, "PageNumber": 1, "PageSize": 20, "RequestId": "34C9E61F-02A0-5EB5-BBCB-16B531ABB9E0", "TotalCount": 1 }
If an Alibaba Cloud CDN API call returns an error, check the error code to verify that your request parameters and values are correct.
You can also use the RequestId or SDK error message from the response with Alibaba Cloud OpenAPI Diagnostics to troubleshoot the issue.