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 ApsaraVideo VOD resources. This topic describes how to use Alibaba Cloud CLI to call ApsaraVideo VOD API operations.
Before you begin
Get yourself familiar with Alibaba Cloud CLI. For more information, see What is Alibaba Cloud CLI?
Prerequisites
An Alibaba Cloud account is created. You can create an Alibaba Cloud account on the Alibaba Cloud official website. We recommend that you create a RAM user to call API operations. For more information, see Create a RAM user.
Install Alibaba Cloud CLI
You must install Alibaba Cloud CLI before you use it. You can install Alibaba Cloud CLI in the Windows, Linux, and macOS operating systems. 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 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
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 use a RAM user to call API operations or perform routine O&M. You need to attach the AliyunVODReadOnlyAccess
policy to the RAM user.
Before you use Alibaba Cloud CLI, you must configure information such as identity credentials and a region ID in Alibaba Cloud CLI. Alibaba Cloud CLI supports various identity credentials. For more information, see Identity credential types. In this example, AccessKey credentials are used. Perform the following steps:
Create a RAM user and grant the RAM user the permissions to manage Alibaba Cloud services based on your business requirements. For more information, see Create a RAM user and Grant permissions to a RAM user.
Create an AccessKey pair for the RAM user and record the
AccessKey ID
andAccessKey secret
for the subsequent configuration of identity credentials. For more information, see Create an AccessKey pair.Obtain and record the ID of an available region for the configuration of identity credentials. Alibaba Cloud CLI uses the region ID that you specify to initiate API calls. For more information about available regions, see Endpoints.
NoteWhen you use Alibaba Cloud CLI, you can specify the
--region
option to run a command in a specific region. If you specify this 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 configuration file named
AkProfile
. For more information, see Configuration examples.
Generate a CLI command
Go to the Debugging page of the ApsaraVideo VOD API.
In the left-side search box of the page that appears, search for the operation that you want to call. On the Parameters tab, configure the parameters based on API documentation. You can click the CLI Example tab on the right to view the generated sample CLI command that contains the specified parameters.
Click the Run icon. You are directed to Cloud Shell. You can debug the command in Cloud Shell.
Click the Copy icon to copy the sample command to the clipboard. You can also paste the sample command into your shell to run.
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, the
--region
option is added to the sample command that is generated in OpenAPI Explorer. When you copy the command to your local shell, Alibaba Cloud CLI ignores the region information in the default credential configurations and environment variable settings, and preferentially runs the command in the specified region. You can delete or retain this 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 extended features of commands. The following common command options are used:
--profile<profileName>
: You can use the--profile
option and theprofileName
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 specify 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 examples
Example 1: The following procedure describes how to use the --help
option to obtain the list of ApsaraVideo VOD API operations supported by Alibaba Cloud CLI. You can also view the API operations that can be called in List of operations by function.
Run the following command:
aliyun vod --help
View the result.
Example 2: The following procedure describes how to use Alibaba Cloud CLI to call the SearchMedia
operation of ApsaraVideo VOD.
Run the following command:
aliyun vod SearchMedia --region cn-shanghai --PageSize 1
View the result.
{ "MediaList": [ { "AiData": {}, "AiRoughData": {}, "AttachedMedia": {}, "Audio": {}, "CreationTime": "2024-08-16T09:36:00Z", "Image": {}, "MediaId": "50798ff*************************", "MediaType": "video", "Video": { "VideoId": "50798ff*************************" } } ], "RequestId": "45D92389-12CA-****-****-************", "ScrollToken": "5a0c898*************************", "Total": 1409 }
If an error is returned after you call the ApsaraVideo VOD API, check whether the request parameters 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.