All Products
Search
Document Center

Function Compute:Configure a NAS file system

Last Updated:May 07, 2025

When using Function Compute, you might need to access the same set of data across different applications and functions. For example, in a machine learning application, a trained model needs to be shared by multiple inference functions. You can configure an Apsara File Storage NAS (NAS) file system to store and share the data. This simplifies data management and addresses limitations of on-premises disk space. After you configure a NAS file system for a function, the function can read data from and write data to the NAS file system in the same way as an on-premises file system.

Prerequisites

Configure the NAS file system

The NAS configuration in Function Compute is at the service level. After you configure a NAS mount target for a service, all functions in the service can access files on the specified NAS file system.

  1. Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.

  2. In the top navigation bar, select a region. On the Services page, find the desired service and click Configure in the Actions column.

  3. In the Storage Configuration section of the Edit Service page, configure the following parameters and click Save.

    存储配置

    • Mount NAS File System: specifies whether to enable the NAS file system. Valid values:

      • Enable: enables the NAS file system.

      • Disable: disables the NAS file system.

    • NAS Configuration Method: the configuration method of the NAS file system. Valid values:

      • Automatic Configuration: The system automatically configures the NAS file system for you.

        Note
        • Before you select Automatic Configuration, you must first allow the function to access resources in the VPC and select a VPC, a VSwitch, and a Security Group. If you do not configure these parameters, the system automatically creates the preceding resources and allocates them to the service. For more information about billing, see VPC billing.

        • If you select Automatic Configuration, the system creates a new general-purpose NAS file system for you. If you select Automatic Configuration again, the system queries the general-purpose NAS file system that was created when you previously selected Automatic Configuration and does not create a new one. For more information about billing, see General-purpose NAS billing.

      • Custom Configuration: You need to manually configure the following parameters to configure the NAS file system.

        • NAS File System: Select a created NAS file system. To create a new NAS file system, click Create NAS File System below and go to the File Storage console to manually create one. Only Network File System (NFS)-based NAS file systems are supported. Server Message Block (SMB)-based NAS file systems are not supported.

        • (Optional) User: Enter a custom user ID in the text box. If you do not enter a value, the system uses the root user ID, which is UID=0. For more information, see NAS users and user groups.

        • (Optional) User Group: Enter a custom user group ID in the text box. If you do not enter a value, the system uses the root user group ID, which is GID=0. For more information, see NAS users and user groups.

        • NAS Mount Target: Select the NAS mount-related configuration and set the related directories. For more information about directory settings, see Configure a NAS mount target.

          • Mount Target: Select a NAS mount target that matches the VPC and vSwitch configured for the current service.

          • Data Transmission Method: Select the normal transmission method or the encrypted transmission method. Only general-purpose NAS supports encrypted transmission. Encrypted transmission encrypts data transmission paths at a cost of certain resources. For more information, see NFS protocol file system transmission encryption.

          • Directory In Remote NAS: For general-purpose NAS, this directory must start with /. For extreme NAS, this directory must start with /share. If the directory that you configure does not exist in the remote NAS, Function Compute automatically creates the directory for you. The directory owner is the user and user group configured above, and the permission level is 777.

          • Local Directory In Function Runtime: Must be a subdirectory of /home, /mnt, or /data.

    Note
    • Before you configure NAS Mount Target, you must first allow the function to access resources in the VPC and select a VPC and a VSwitch in the same region. For more information, see Configure the network.

    • A maximum of five NAS mount targets can be configured for a service.

NAS users and user groups

When you configure a NAS mount target for a function, you must first configure a UserID value and a GroupID value. The two values are equivalent to a user and a user group in NAS. You must specify the same read and write permissions on files when you configure the file owner and the corresponding group permissions based on your business requirements.

Valid values of UserID and GroupID range from 0 to 65534. UserID and GroupID values are optional. If you do not enter a UserID value, the system uses the root user ID, which is 0. The default UserID value is 0. If you do not enter a GroupID value, the system uses the root group ID, which is 0.

When Function Compute uses non-root permissions to execute user code, if you need to mount a subdirectory of the remote NAS file system, you must make sure that the execution user in the function instance has the read and write permissions on the subdirectory. We recommend that you use one of the following methods to mount a subdirectory of the remote NAS file system:

  • Mount a root directory of the remote NAS file system by using a NAS instance. For more information, see Configure the NAS file system.

    After the mount operation is successful, use the following example to create a subdirectory, such as fc-1. Then, change the Directory In Remote NAS in the NAS mount target from the root directory to the created subdirectory (from / to /fc-1) to mount the remote subdirectory.

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import os
    
    def handler(event, context):
      print('uid : ' + str(os.geteuid()))
      print('gid : ' + str(os.getgid()))
    
      # Change the value to the local directory in the on-premises file system to which the NAS file system is mounted.
      local_nas_dir = "/home/app"
      # Change the value to the name of the destination subdirectory.
      target_sub_dir = "fc-1"
    
      # Create the destination subdirectory by using the permissions of the current instance in Function Compute.
      new_dir = local_nas_dir + '/' + target_sub_dir + '/'
      print('new_dir : ' + str(new_dir))
    
      os.mkdir(new_dir)
      return 'success'

    挂载子目录

  • Mount a NAS file system by using an ECS instance. For more information, see Mount a NAS file system by using an ECS instance.

    After the mount operation is successful, create a subdirectory and then run the chmod 777 command to grant permissions to the subdirectory.

Note
  • The default user and user group do not have the read and write permissions on files. Therefore, we recommend that you set UserID and GroupID to a value ranging from 1 to 65534. Then, different functions in the service can share these file resources.

  • The permissions on files that are uploaded to NAS are the same as the permissions on on-premises files.

Configure a NAS mount target

Each NAS Mount Target address consists of a Directory In Remote NAS and a Local Directory In Function Runtime. A local directory in the on-premises file system is mapped to a remote directory in a NAS file system.

  • Directory In Remote NAS

    A directory in the remote NAS file system refers to the directory of the NAS file system that the service needs to access. The directory consists of a mount target and an absolute directory. You can add mount targets in the NAS console. You can assemble a mount target and an absolute directory into a remote directory. For example, if the mount target of the NAS file system is xxxx-nas.aliyuncs.com and the absolute directory that you want to access is /workspace/document, the complete remote directory is xxxx-nas.aliyuncs.com:/workspace/document.

    You can log on to the NAS console, click the target file system in the file system list, and then click Mount to obtain the mount target from the mount target list.

  • Local Directory In Function Runtime

    The local directory in a function runtime refers to the mount target of a local file system. You cannot use common Linux and Unix system directories such as bin, opt, var, or dev to mount a NAS file system. Function Compute allows you to mount a NAS file system to non-system directories such as mnt, home, or data.

More information

Apart from using the Function Compute console, you can also use Serverless Devs to mount a NAS file system. For more information, see Use s nas commands to mount a disk.