CLI integration examples
The Alibaba Cloud CLI is a general-purpose command-line tool built on OpenAPI. You can use the Alibaba Cloud CLI to interact with the Cloud Parallel File System (CPFS) service and manage your CPFS resources in a shell. This topic describes how to use the Alibaba Cloud CLI to call CPFS APIs and provides examples.
Background information
If you are not familiar with the Alibaba Cloud CLI, see What is Alibaba Cloud CLI?.
Install Alibaba Cloud CLI
Before you can use the Alibaba Cloud CLI, you must install it. The Alibaba Cloud CLI provides installation packages for Windows, Linux, and macOS. Choose the installation method for your operating system.
You can also use Cloud Shell, provided by Alibaba Cloud, to debug Alibaba Cloud CLI commands. For more information about Cloud Shell, see What is Cloud Shell?.
Configure Alibaba Cloud CLI
The primary Alibaba Cloud account has full administrative and access permissions for all product APIs, which poses a high security risk. We strongly recommend that you create and use a RAM user for API access and daily operations. The RAM user must be granted the AliyunNASFullAccess permission to manage Cloud Parallel File System (CPFS).
You must configure your credentials and a region ID before using the Alibaba Cloud CLI. The Alibaba Cloud CLI supports various types of credentials. For more information, see Configure and manage credentials. The following procedure uses AccessKey credentials as an example:
-
Create a RAM user and grant the required permissions to manage the corresponding products. For more information, see Create a RAM user and Manage permissions for RAM users.
-
After you create and grant permissions to the RAM user, create an AccessKey for the user. Record the
AccessKey IDandAccessKey Secretto configure your credentials. For more information, see Create an AccessKey. -
When you configure credentials, you must also set a region ID. The Alibaba Cloud CLI uses this region to make API calls. For a list of available regions, see Endpoints.
NoteWhen you use the Alibaba Cloud CLI, you can use the
--regionoption to specify a region for a command. This option overrides the region information in your default credential profile and environment variables. For more information, see Command-line options. -
Use the RAM user's AccessKey to configure your credentials in a profile named
AkProfile. For more information, see Configure and manage credentials.
Generate CLI examples
-
Go to the list of NAS/CPFS APIs.
-
On the API debugging page, search for the API you want to use in the search box on the left. In the Parameter section, enter the required parameter values. Click the CLI Sample tab to the right of the Parameter section to generate a command example with the specified parameters.
-
Click Run Command to open Cloud Shell and quickly debug the command.
-
Click Copy to copy the CLI example to the clipboard. You can then paste it into your local shell and run it.
-
If you copy a CLI example to your local shell for debugging, ensure the parameter format is correct. For details about Alibaba Cloud CLI parameter formats, see Parameter formats.
-
The sample generated by the OpenAPI portal includes the
--regionoption by default. When you copy the command to run it locally, the Alibaba Cloud CLI uses the specified region and ignores the region settings in your default credential profile and environment variables. You can remove or keep this option as needed.
-
-
Calling CPFS APIs
Command structure
The general command structure for the Alibaba Cloud CLI is as follows: For more information, see Generate and run commands.
aliyun <command> <subcommand> [options and parameters]
Common command options
You can use command-line options to change the default behavior of a command or provide additional capabilities. Common options include:
-
--profile<profileName>: This option overrides the default credential profile and any credential-related environment variables. -
--help: Add this option to any command to view its help information. For more information, see Get help.
For more information, see Command-line options.
Examples
This example uses Windows Command Prompt. Parameter formats may differ on other operating systems, so ensure you use the correct format. For more information, see Parameter formats.
-
Example 1: Call the
CreateFileSystemcommand to create a Cloud Parallel File System (CPFS) file system with a baseline performance of 100 MB/s/TiB in availability zone C of the China (Zhangjiakou) region.-
Run the command.
aliyun nas CreateFileSystem --FileSystemType cpfs --ChargeType PayAsYouGo --StorageType advance_100 --ProtocolType cpfs --VpcId 'vpc-8vbqmlw7s97hu0q1d****' --VSwitchId 'vsw-8vbmuylc3di7980tj****' --ZoneId 'cn-zhangjiakou-c' --Capacity 3600 -
Output:
{ "FileSystemId": "cpfs-09b7d2b3149c****", "RequestId": "AEEABA87-2F97-5CB9-AA06-D438A78C6BBD" }
-
-
Example 2: Use the
--helpoption to list the CPFS APIs supported by the Alibaba Cloud CLI. You can also view the supported APIs in the API overview.-
Run the command.
aliyun nas --help -
Output:
PS E:\> aliyun nas --help 阿里云CLI命令行工具 3.0.207 Usage: aliyun nas <ApiName> --parameter1 value1 --parameter2 value2 ... Product: NAS (File Storage (NAS/CPFS) ) Version: 2017-06-26 Available Api List: AddClientToBlackList Adds a client to the blocklist of a CPFS service to block its write requests, which implements an I/O fence. AddTags Adds or overwrites one or more tags for a file system instance. ApplyAutoSnapshotPolicy Applies an auto snapshot policy to one or more file systems. ApplyDataFlowAutoRefresh Configures automatic refresh for a specified data flow. CancelAutoSnapshotPolicy Cancels the auto snapshot policy for one or more file systems. CancelDataFlowAutoRefresh Cancels the automatic refresh configuration for a specified data flow. CancelDataFlowTask Cancels a data flow task that has not been executed.
-
If an API call returns an error, use the error code to verify your request parameters and their values.
You can also use the RequestID from the response or the SDK error message to troubleshoot the issue on the Alibaba Cloud OpenAPI Developer Portal.