All Products
Search
Document Center

Use fun nas to manage Apsara File Storage NAS files

Last Updated: Mar 20, 2020

This topic describes how to create an Apsara File Storage NAS file system and its dependent resources, as well as how to manage NAS files after creation.

Background information

Use the NasConfig: Auto property to create a NAS file system and its dependent VPC resources by one click

You can store large-scale and fixed resources in NAS when you use Function Compute. In this way, you can quickly develop a serverless application with dependencies on large-scale resources. However, the complex configurations of NAS makes it more difficult to use Function Compute. To simplify the NAS configuration process, Function Compute has added the NasConfig: Auto property to Fun. You can use this property to create a NAS file system and its dependent VPC resources by one click.

Use the fun nas commands to manage NAS files and upload local NAS files

After NAS configuration is complete, you can upload local resources to the NAS file system.

You can use one of the following methods to upload resources to a NAS file system:

You can also use the simpler fun nas commands to manage NAS files and upload local NAS files.

The fun nas commands provide an upgraded version of the third method to solve the following problems:

  • A service must be manually deployed.
  • Directories cannot be uploaded.
  • Files larger than 6 MB cannot be uploaded.

Deploy a NAS file system

Traditional deployment method

Procedure

  1. Log on to the VPC console and create the following components sequentially:

  2. A VPC

  3. A VSwitch

  4. A security group

  5. Log on to the NAS console and perform the following operations sequentially:

  6. Create a file system.

  7. Add a mount target.

  8. Specify the VpcConfig and the NasConfig parameters in the template.yml file based on the preceding resources.

    The content of the template.yml file is as follows:

    1. ROSTemplateFormatVersion: '2015-09-01'
    2. Transform: 'Aliyun::Serverless-2018-04-03'
    3. Resources:
    4. nasDemo:
    5. Type: 'Aliyun::Serverless::Service'
    6. Properties:
    7. VpcConfig:
    8. VpcId: 'vpc-bp12hm92gdpcjtai7****'
    9. VSwitchIds: [ 'vsw-bp1gitru7oicyyb4u****' ]
    10. SecurityGroupId: 'sg-bp1243pi65bw4cjj****'
    11. NasConfig:
    12. UserId: 10003
    13. GroupId: 10003
    14. MountPoints:
    15. - ServerAddr: '012194b28f-ujc20.cn-hangzhou.nas.aliyuncs.com:/'
    16. MountDir: '/mnt/nas'

After you have completed the preceding steps, you can use the fun local or fun deploy commands for debugging and deployment.

New deployment method

If you want to use NAS without worrying about VPC, VSwitch, or mount target configurations, you can use the new property NasConfig: Auto.

You can edit the template.yml file as the following example to use the NasConfig service.

  1. ROSTemplateFormatVersion: '2015-09-01'
  2. Transform: 'Aliyun::Serverless-2018-04-03'
  3. Resources:
  4. nasDemo:
  5. Type: 'Aliyun::Serverless::Service'
  6. Properties:
  7. NasConfig: Auto

The NasConfig: Auto property frees you from VPC and NAS configurations. Fun automatically configures them when you run the fun deploy commands.

The deployment log is as follows:

  1. Waiting for service nasDemo to be deployed...
  2. ... ...
  3. using 'VpcConfig: Auto', Fun will try to generate related vpc resources automatically
  4. ... ...
  5. generated auto VpcConfig done: {"vpcId":"vpc-bp1pcr7o8ksmgojt4****","vswitchIds":["vsw-bp13qdw9qe1i2it4y****"],"securityGroupId":"sg-bp161u0547x0lq5k****"}
  6. using 'NasConfig: Auto', Fun will try to generate related nas file system automatically
  7. ... ...
  8. generated auto NasConfig done: {"UserId":10003,"GroupId":10003,"MountPoints":[{"ServerAddr":"****c4a7ac-vrk7.cn-hangzhou.nas.aliyuncs.com:/nasDemo","MountDir":"/mnt/auto"}]}
  9. Checking if nas directories /mnt/auto/nasDemo exists, if not, it will be created automatically
  10. Checking nas directories done ["/mnt/auto/nasDemo"]
  11. ... ...
  12. service nasDemo deploy success

As the deployment log displays, the new deployment method has three more steps than the traditional deployment method because of the NasConfig: Auto property:

  1. Automatically creates VPC resources.
  2. Automatically creates NAS resources.
  3. Checks whether the mount directory configured by Function Compute exists. If there is no mount directory, Function Compute automatically creates one.

You can use NAS directly in Function Compute after the preceding three steps are performed automatically.

Note:

  • The result of NasConfig: Auto is idempotent. If the dependent resources do not exist, they will be created automatically. If the dependent resources already exist, they will be directly used.
  • fun local and fun deploy both support NasConfig: Auto.
  • When you use NasConfig: Auto, the NAS file system is attached automatically to the /mnt/auto directory of the Function Compute runtime.

Usage

This section provides an example on how to create a Fun project and use the features of fun nas.

Prerequisites

A blank directory is created. A file named template.yml is created under the directory to add NAS configurations.

The content of the template.yml file is as follows:

  1. ROSTemplateFormatVersion: '2015-09-01'
  2. Transform: 'Aliyun::Serverless-2018-04-03'
  3. Resources:
  4. NasDemo:
  5. Type: 'Aliyun::Serverless::Service'
  6. Properties:
  7. NasConfig: Auto

Procedure

  1. Run the fun nas init command under the directory to initialize the configurations.

    1. $ fun nas init
    2. start fun nas init...
    3. Waiting for service fun-nas-NasDemo to be deployed...
    4. ... ...
    5. using 'VpcConfig: Auto', Fun will try to generate related vpc resources automatically
    6. ... ...
    7. generated auto VpcConfig done: {"vpcId":"vpc-bp1pcr7o8ksmgojt4****","vswitchIds":["vsw-bp13qdw9qe1i2it4y****"],"securityGroupId":"sg-bp161u0547x0lq5k****"}
    8. using 'NasConfig: Auto', Fun will try to generate related nas file system automatically
    9. ... ...
    10. generated auto NasConfig done: {"UserId":100**,"GroupId":100**,"MountPoints":[{"ServerAddr":"****c4a6d9-gry74.cn-hangzhou.nas.aliyuncs.com:/fun-nas-NasDemo","MountDir":"/mnt/auto"}]}
    11. Checking if nas directories /mnt/auto/fun-nas-NasDemo exists, if not, it will be created automatically
    12. Checking nas directories done ["/mnt/auto/fun-nas-NasDemo"]
    13. ... ...
    14. service fun-nas-NasDemo deploy success
    15. Fun nas init Success
    16. Tips for next step
    17. ======================
    18. $ fun nas info # Show NAS info
    19. $ fun nas ls # List NAS files
    20. $ fun nas sync # Synchronize files to nas
    21. $ fun deploy # Deploy Resources

After fun nas init is run, Fun creates the NAS and VPC resources. Then, you can run other fun nas commands.

Note: You must run fun nas init again after you have modified NAS configurations.

  1. Run fun nas info to view the local NAS directory.

    1. $ fun nas info
    2. Local NAS folder of service NasDemo includes:
    3. /NasDemo/.fun/nas/auto-default/NasDemo

    Note: The local NAS directory acts as a synchronization disk. You can store files and resources in this directory and run fun nas sync to synchronize these resources arranged in the local directory structure to a NAS file system.

  2. Run fun nas sync to synchronize local NAS resources to the NAS file system after you have saved the files you want to upload to the corresponding local directory as described in the previous step.

    1. $ fun nas sync
    2. Starting upload /NasDemo/.fun/nas/auto-default/NasDemo to nas://NasDemo:/mnt/auto/
    3. NAS path checking...
    4. zipping /NasDemo/.fun/nas/auto-default/NasDemo
    5. /NasDemo/.fun/nas/auto-default/.NasDemo.zip - zipped
    6. generate tmpDir: /NasDemo/.fun/nas/auto-default/.fun_nas_tmp/42658c92eef63f2b3b13e5f46315ee7d
    7. Split zip file to 1 small files
    8. Uploading...
    9. Upload /NasDemo/.fun/nas/auto-default/NasDemo to /mnt/auto/ done!

Note: You must run fun nas sync again after you have changed the NAS files stored in the local directory.

  1. Run fun nas ls to view files in the NAS file system.

    fun nas ls supports the following formats:

    • Displays the files pointed by the NAS path under a service: fun nas ls nas://ServiceName/Path In this example, the path can be nas://NasDemo/mnt/auto.

    • If the template.yml file only contains one service, the ServiceName parameter can be omitted. It is in the fun nas ls nas:///Path format. In this example, the path can be nas:///mnt/auto.

Run fun nas ls nas://NasDemo/mnt/auto to view resources in the NAS file system.

  1. ```shell
  2. $ fun nas ls -a nas://NasDemo/mnt/auto
  3. total 10
  4. drwxr-xr-x 4 user10003 10003 4096 Aug 4 11:38 .
  5. drwxr-xr-x 1 root root 4096 Aug 4 11:37 ..
  6. drwxr-xr-x 4 user10003 10003 4096 Aug 4 11:38 .fun_nas_tmp
  7. -rw-r--r-- 1 user10003 10003 19 Aug 4 11:38 test
  8. drwxr-xr-x 2 user10003 10003 4096 Aug 4 11:38 testDir
  9. ```

Demo