All Products
Search
Document Center

File Storage NAS:CLI integration example

Last Updated:Nov 01, 2024

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

Important

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:

  1. 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 Grant permissions to a RAM user.

  2. Create an AccessKey pair for the RAM user and record the AccessKey ID and AccessKey secret for the subsequent configuration of identity credentials. For more information, see Create an AccessKey pair.

  3. Specify a region ID. Alibaba Cloud CLI calls API operations in the specified region. For more information about available regions, see Endpoints.

  4. Use the AccessKey pair of the RAM user to configure identity credentials in the configuration file named AkProfile. For more information, see Configuration examples.

Generate a CLI command

  1. Log on to OpenAPI Portal and click File Storage NAS.

  2. In the left-side search box of the API debugging page, search for the API operation that you want to call. On the Parameters tab of the API operation, specify the parameters based on the API reference. Click the CLI Example tab on the right side of the Parameters tab to view the generated sample command that contains the specified parameters.

    image

    • Click the Run Command icon to start Cloud Shell and debug the command in Cloud Shell.

    • Click the Copy icon to copy the sample command to the clipboard. You can paste the sample command into your shell tool to run the sample command.

      • 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 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 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 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 the extended features of commands. The following command options are frequently used:

  • --profile<profileName>: After you use the --profile option and its parameter profileName to 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 --help option to obtain the help information about a command. For more information, see Use the help command.

Examples

Note

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 Parameter formats.

  • Example 1: Use Alibaba Cloud CLI to call the CreateFileSystem operation of NAS to create a pay-as-you-go General-purpose Capacity Network File System (NFS) file system.

    1. Run the following command:

      aliyun nas CreateFileSystem --FileSystemType standard --ChargeType PayAsYouGo --StorageType Capacity --ProtocolType NFS
    2. View the command output.

      {
              "FileSystemId": "6a2464****",
              "RequestId": "3879AB9C-1DED-5A49-A015-350138B23BF0"
      }
  • Example 2: Use Alibaba Cloud CLI to call the CreateAccessGroup operation of NAS to create a permission group named vpc_test.

    1. Run the following command:

      aliyun nas CreateAccessGroup --AccessGroupName vpc_test --AccessGroupType Vpc
    2. View the command output.

      {
              "AccessGroupName": "vpc_test",
              "RequestId": "95CB3005-C251-5E11-A949-29CB2C7A9C54"
      }
Note

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 perform self-service diagnostics based on the returned request ID or SDK error information on the OpenAPI problem diagnosis page.