Use Alibaba Cloud CLI to manage resources
Alibaba Cloud CLI is a command-line tool built on OpenAPI that lets you manage ApsaraVideo VOD resources from the terminal. This topic covers the setup steps and call examples.
Before you begin
Familiarize yourself with Alibaba Cloud CLI. For more information, see What is Alibaba Cloud CLI
Prerequisites
Before you use Alibaba Cloud CLI, make sure that you have an Alibaba Cloud account. If you do not have one, go to the Alibaba Cloud official website to register an Alibaba Cloud account (root account). We recommend that you create a RAM user for API access. For more information, see Create a RAM user.
Install Alibaba Cloud CLI
Install Alibaba Cloud CLI before you use it. Select an installation package based on your operating system. For more information, see the following topics:
-
Windows operating system: Install Alibaba Cloud CLI on Windows
-
Linux operating system: Install, update, and uninstall Alibaba Cloud CLI
-
macOS operating system: Install Alibaba Cloud CLI on macOS
You can also use Cloud Shell to debug CLI commands online. For more information, see What is Cloud Shell
Configure Alibaba Cloud CLI
An Alibaba Cloud account has full permissions to manage all services. Using it directly to call API operations poses security risks. We recommend that you use a RAM user with the AliyunVODReadOnlyAccess policy attached.
Before you use Alibaba Cloud CLI, configure identity credentials and a region ID. Alibaba Cloud CLI supports various identity credentials. For more information, see Identity credential types. This example uses AccessKey credentials. 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 Manage RAM user permissions.
-
Create an AccessKey pair for the RAM user and record the
AccessKey IDandAccessKey secretfor later use. For more information, see Create an AccessKey. -
Obtain and record a valid region ID. Alibaba Cloud CLI uses this region ID to initiate API calls. For more information about available regions, see Endpoints.
NoteWhen you use Alibaba Cloud CLI, you can specify the
--regionoption to run a command in a specific region. This option overrides the region in the default credential configurations and environment variable settings. For more information, see Command-line options. -
Use the RAM user's AccessKey pair to configure credentials in the profile named
AkProfile. For more information, see Configure and manage credentials.
Generate a CLI command
-
Go to the ApsaraVideo VOD page in OpenAPI Explorer.
-
In the left-side search box, search for the operation that you want to call. On the Parameters tab, configure the parameters. Click the CLI Example tab on the right to view the generated CLI command with the specified parameters.
For example, if you set PageSize to 100, the generated sample CLI command is aliyun vod SearchMedia --region cn-shanghai --PageSize 100.
-
Click the Run icon to open Cloud Shell, where you can debug the command.
-
Click the Copy icon to copy the command to the clipboard and paste it into your shell.
-
When you paste the command into your shell, check the parameter formats. For more information, see Understand command parameters.
-
By default, the
--regionoption is included in the command generated in OpenAPI Explorer. When you copy this command to your local shell, the specified region overrides the default credential and environment variable settings. You can remove or keep this option as needed.
-
Call an API operation
Syntax
In Alibaba Cloud CLI, run commands using the following syntax. For more information, see Generate and run CLI commands with OpenAPI Explorer.
aliyun <command> <subcommand> [options and parameters]
Command options
You can specify command options to change command behavior or enable extended features. The following common options are used:
-
--profile<profileName>: Specifies a configuration profile. When a valid profile is specified, Alibaba Cloud CLI uses its configurations instead of the default credentials or environment variable settings. -
--help: Displays help information for a command. For more information, see Use the help command.
For more information, see Command-line options.
Call examples
Example 1: Use the --help option to list the ApsaraVideo VOD API operations supported by Alibaba Cloud CLI. You can also view the available operations in API overview.
-
Run the following command:
aliyun vod --help -
View the result.
Usage:
aliyun vod <ApiName> --parameter1 value1 --parameter2 value2 ...
Product: vod (ApsaraVideo VOD)
Version: 2017-03-21
Available Api List:
AddAITemplate Adds an AI template for automated review and smart thumbnail tasks.
AddCategory Creates a video category.
AddEditingProject Creates an online editing project.
AddEditingProjectMaterials
AddTranscodeTemplateGroup Creates a transcoding template group or adds transcoding templates to a transcoding template group.
AddVodDomain Adds a domain name to accelerate in ApsaraVideo VOD.
AddVodStorageForApp Adds a storage bucket to an ApsaraVideo VOD application.
AddVodTemplate Creates a snapshot template.
Example 2: 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, verify that the request parameters are valid based on the error code.
You can also record the Request ID or SDK error message from the response and use Alibaba Cloud OpenAPI Diagnostics to troubleshoot the issue.