Alibaba Cloud Command Line Interface (CLI) is a general-purpose command-line tool that is developed based on APIs. You can use Alibaba Cloud CLI to interact with File Storage NAS (NAS) and manage your NAS resources by using a shell tool. This topic describes how to use Alibaba Cloud CLI to call NAS API operations.
Background information
For more information about Alibaba Cloud CLI, see What is Alibaba Cloud CLI
Install Alibaba Cloud CLI
You must install Alibaba Cloud CLI before you can use Alibaba Cloud CLI. You can install Alibaba Cloud CLI on 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 permissions to call all API operations. Using an Alibaba Cloud account to perform operations is a high-risk operation. We recommend that you call API operations or perform routine O&M as a Resource Access Management (RAM) user. You must attach the AliyunNASFullAccess policy to the RAM user.
Before you use Alibaba Cloud CLI, you must configure credential 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 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 the subsequent configuration of identity credentials. For more information, see Create an AccessKey.-
Specify a region ID. Alibaba Cloud CLI calls API operations in the specified region. For more information about available regions, see Endpoints.
Use the AccessKey pair of the RAM user to configure identity credentials in the configuration file named
AkProfile. For more information, see Configure and manage credentials.
Generate a CLI command
-
Log on to the OpenAPI Portal.
-
On the API debugging page, you can search for the API that you want to use in the search box on the left. In the Parameter Configuration section, enter the parameters according to the API documentation, and then click the CLI Example tab to the right of Parameter Configuration to generate a command example with the parameters.
-
Click Run Command to open Cloud Shell and quickly debug the command.
-
Click Copy to copy the command example to your clipboard. You can then paste it into your local shell tool to run it.
Pay attention to the parameter formats when you copy and paste the CLI command to the local shell. For more information about the parameter formats of Alibaba Cloud CLI, see Understand command parameters.
By default, the
--regionoption is added to the sample command that is generated in OpenAPI Explorer. When you copy the command to your shell tool, 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.
-
Use Alibaba Cloud CLI to call NAS API operations
Syntax
In Alibaba Cloud CLI, you can use the following syntax to run commands. For more information, see Generate and run CLI commands with OpenAPI Explorer.
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 the extended features of commands. The following command options are frequently used:
--profile<profileName>: After you use the--profileoption and its parameterprofileNameto specify a configuration profile, Alibaba Cloud CLI ignores the default identity credential and environment variable configurations and uses the configurations that you specify to run commands.--help: You can specify the--helpoption to obtain the help information about a command. For more information, see Use the help command.
Examples
In the following examples, commands are run in Command Prompt of Windows. The parameter formats of commands vary on other operating systems. For more information about the parameter formats of Alibaba Cloud CLI, see Understand command parameters.
Example 1: Use Alibaba Cloud CLI to call the
CreateFileSystemoperation of NAS to create a pay-as-you-go General-purpose Capacity Network File System (NFS) file system.Run the following command:
aliyun nas CreateFileSystem --FileSystemType standard --ChargeType PayAsYouGo --StorageType Capacity --ProtocolType NFSView the command output.
{ "FileSystemId": "6a2464****", "RequestId": "3879AB9C-1DED-5A49-A015-350138B23BF0" }
Example 2: Use Alibaba Cloud CLI to call the
CreateAccessGroupoperation of NAS to create a permission group namedvpc_test.Run the following command:
aliyun nas CreateAccessGroup --AccessGroupName vpc_test --AccessGroupType VpcView the command output.
{ "AccessGroupName": "vpc_test", "RequestId": "95CB3005-C251-5E11-A949-29CB2C7A9C54" }
If an error is returned after you call an API operation of NAS, you must check whether the request parameters and their values are valid based on the returned error code.
You can also use the RequestID or SDK error message from the response with the OpenAPI Diagnostic Platform to diagnose the issue.