Alibaba Cloud CLI is a general-purpose command-line tool that is developed based on APIs. You can use Alibaba Cloud CLI to implement automatic management and maintenance of ApsaraVideo Live resources. This topic describes how to use Alibaba Cloud CLI to call the API operations of ApsaraVideo Live. In this example, the DescribeLiveUserDomains
operation is called to query the domain names of ApsaraVideo Live within the account.
Before you begin
Get yourself familiar with Alibaba Cloud CLI. For more information, see What is Alibaba Cloud CLI?
Step 1: Install Alibaba Cloud CLI
You must install Alibaba Cloud CLI before you can use it. 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:
You can also use Cloud Shell to debug the commands that you want to run in Alibaba Cloud CLI. Alibaba Cloud CLI is built into Cloud Shell, which regularly updates the software version. For more information, see What is Cloud Shell?.
Step 2: Configure Alibaba Cloud CLI
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 a Resource Access Management (RAM) identity, grant the required permissions to the RAM identity based on the principle of least privilege, and then use the RAM identity to call API operations. For more information about the policies supported by ApsaraVideo Live, see ApsaraVideo Live system policies and ApsaraVideo Live custom policies.
Before you use Alibaba Cloud CLI, you must configure information such as identity credentials and region IDs in Alibaba Cloud CLI. Alibaba Cloud CLI supports various types of identity credentials. For more information, see Credential types. In this example, AccessKey pairs are used as identity credentials.
Create a RAM user and create an AccessKey pair for the RAM user to configure identity credentials. For more information, see Create a RAM user and Create an AccessKey pair.
Grant the required permissions to the RAM user. In this example, attach the
AliyunLiveReadOnlyAccess
policy to the RAM user. The policy grants the RAM user the read-only permissions on ApsaraVideo Live. For more information, see Grant permissions to a RAM user.Obtain the ID of the region in which you want to configure identity credentials. Alibaba Cloud CLI uses the specified region ID to initiate API calls. For more information about the available regions of ApsaraVideo Live, see Endpoints.
NoteWhen 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.Use the AccessKey pair of the RAM user to configure AccessKey credentials in the profile named
AkProfile
. For more information, see Configuration examples.
Step 3: Generate a CLI command
In OpenAPI Explorer, call the DescribeLiveUserDomains operation.
On the Parameters tab, configure the parameters. Then, click the CLI Example tab to view the generated sample CLI command.
Copy the CLI command or debug the CLI command in Cloud Shell.
Click the icon to start Cloud Shell and debug the CLI command in Cloud Shell.
Click the icon to copy the CLI command to the clipboard. You can also paste the CLI command into your on-premises shell to run the command.
NoteWhen you paste the CLI command into your on-premises shell for debugging, take note of the parameter formats. For more information about the parameter formats required by 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.
Step 4: Call the API operations of ApsaraVideo Live
Example 1: Query the supported API operations of ApsaraVideo Live by using Alibaba Cloud CLI
The following example shows how to use the --help
option to query the supported API operations of ApsaraVideo Live. You can also view the supported API operations in List of operations by function.
Run the following command:
aliyun live --help
View the command output.
Example 2: Query all domain names of ApsaraVideo Live within the account
The following example shows how to use Alibaba Cloud CLI to call the DescribeUserDomains
operation of ApsaraVideo Live to query all domain names within the account.
Run the following command:
aliyun live DescribeLiveUserDomains --LiveDomainType liveVideo
View the command output.
{ "Domains": { "PageData": [ { "Cname": "learn.developer.aliyundoc.com", "Description": "test", "DomainName": "demo.aliyundoc.com", "GmtCreated": "2017-08-29T12:15:36Z", "GmtModified": "2017-12-29T12:15:36Z", "LiveDomainStatus": "online", "LiveDomainType": "liveVideo", "RegionName": "cn-beijing", "ResourceGroupId": "" } ] }, "PageNumber": 1, "PageSize": 100, "RequestId": "E4EBD2BF-5EB0-4476-8829-9D94E1B15267", "TotalCount": 1 }
NoteIf an error is returned after you call an API operation of ApsaraVideo Live, check whether the input parameters and values are valid based on the error code.
You can also perform self-service diagnostics based on the returned request ID or SDK error information on the OpenAPI problem diagnosis page.