All Products
Search
Document Center

Function Compute:Configure a NAS file system

Last Updated:Apr 18, 2026

In Function Compute, you might need multiple applications or functions to access a shared dataset. For example, in machine learning, a trained model may need to be shared among several inference functions. You can configure a File Storage NAS file system for your function to store this data. This enables file sharing, simplifies data management, and overcomes local disk space limitations. After you configure a File Storage NAS file system, your function can read and write NAS files just as it would a local file system.

Prerequisites

  • Function Compute

    You have created a function and configured it to access a VPC. For more information, see Create a function and Configure network settings.

    Note

    You can add NAS mount targets only within a private VPC. When you configure network settings, you must allow the function to access VPC resources and select the correct VPC. Otherwise, the function cannot access the specified NAS file system.

  • File Storage NAS

    You have created a NAS file system and added a mount target. For more information, see Create a file system and Create a mount target.

Limitations

  • A Function Compute function in a single region supports a maximum of five NAS mount targets and five Object Storage Service (OSS) mount targets.

  • The local directories specified for NAS and OSS mount targets cannot overlap within the function's execution environment.

Configure a NAS file system

  1. Log on to the Function Compute console. In the left-side navigation pane, choose Function Management > Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the name of your target function.

  3. On the function details page, click the Configuration tab. Click Modify next to Advanced Settings. In the Advanced Settings panel, find the Storage section, turn on the Mount NAS file system switch, configure the parameters, and then click Deploy.

    You can configure the file system by using either Automatic Configuration or Custom Configuration.

    Automatic configuration

    The system automatically creates a general-purpose NAS file system named Alibaba-Fc-V3-Component-Generated, along with a VPC, vSwitch, and security group of the same name.

    The next time you select Automatic Configuration in the same region, the system finds and reuses the existing file system and its related VPC resources instead of creating new ones. For billing details, see VPC Pricing and General-purpose NAS pricing.

    Custom configuration

    You manually select a NAS file system and configure its parameters, such as the user, user group, and mount target.

    The following table describes the key parameters.

    Parameter

    Description

    Example

    NAS

    Select an existing NAS file system.

    To create a new file system, click Create NAS File System. You are then redirected to the NAS console to create it.

    Important

    Only file systems that use the Network File System (NFS) protocol are supported. The Server Message Block (SMB) protocol is not supported.

    01d394****

    User, User Group

    Enter a custom user ID (UID) and user group ID (GID). If you leave these fields empty, the system defaults to the root user (UID=0 and GID=0). For more information, see NAS user and user group.

    1

    Remote Directory

    • For a general-purpose NAS file system, the directory must start with /.

    • For an extreme NAS file system, the directory must start with /share.

    If the specified directory does not exist on the remote NAS file system, Function Compute automatically creates it. The directory owner is the user and user group that you configured, and the permissions are set to 777.

    For more information, see Remote directory.

    /

    Local directory of a function

    Use a subdirectory of /home, /mnt, /tmp, or /data.

    Note

    Do not use common Linux and Unix system directories or their subdirectories, such as /bin, /opt, /var, or /dev. Otherwise, the mount may fail.

    For more information, see Local directory.

    /mnt/nas

    Note
    • If you want multiple functions to share resources on the same NAS file system, you must configure them with the same user and user group.

    • Files uploaded to NAS retain their local permissions.

Verify the NAS mount

Prepare the function code

After you configure the NAS file system, you can access the NAS file system in your code by using the local directory path that you specified during the mount.

  1. On the function details page, click the Code tab. Enter the code in the code editor and click Deploy.

    The following Python event function code provides an example of writing content to and reading content from a NAS file.

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import random
    import subprocess
    import string
    import os
    
    
    def handler(event, context):
        # report file system disk space usage and check NAS mount target
        out, err=subprocess.Popen(['df', '-h'], stdout=subprocess.PIPE).communicate()
        print('disk: ' + str(out))
        lines = [ l.decode() for l in out.splitlines() if str(l).find(':') != -1 ]
        nas_dirs = [ x.split()[-1] for x in lines ]
        print('uid : ' + str(os.geteuid()))
        print('gid : ' + str(os.getgid()))
    
        for nas_dir in nas_dirs:
            sub_dir = randomString(16)
            file_name = randomString(6)+'.txt'
            new_dir = nas_dir + '/' + sub_dir + '/'
            print('test file: ' + new_dir + file_name)
            # Write data to the NAS file.
            content = "NAS here I come"
            os.mkdir(new_dir)
            fw = open(new_dir + file_name, "w+")
            fw.write(content)
            fw.close()
            # Display the folder tree in the NAS directory
            for home, dirs, files in os.walk(nas_dir):
                level = home.replace(nas_dir, '').count(os.sep)
                indent = ' ' * 2 * (level)
                print('{}{}/'.format(indent, os.path.basename(home)))
                subindent = ' ' * 2 * (level + 1)
                for f in files:
                    print('{}{}'.format(subindent, f))
            # Read data from the NAS file.
            f = open(new_dir + file_name, "r")
            print(f.readline())
            f.close()
        
        return 'success'
    
    
    def randomString(n):
        return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(n))
      

Verify the result

  1. After the code is deployed, click Test Function on the Code tab.

    After the execution is complete, you can view the result at the bottom of the Code tab. On the Log Output tab, you can see that the function successfully wrote to and read from the NAS file.

    image

  2. (Optional) After the operations are complete, log on to an instance to check the files in the local directory. Confirm that the NAS files match the log output from the previous step.

    1. On the function details page, click the Instance tab. In the Actions column for the target instance, click Connect to Instance.

      If no instances are running, click Test Function on the Code tab to run the function again. This action creates an instance.

    2. After you log on to the instance, you can run commands to view the files in the configured local directory. The following figure shows an example.

      image

Key concepts

NAS users and user groups

Valid values for User ID (UID) and Group ID (GID) are in the range [0, 65534]. If you do not specify values, both default to 0, representing the root user ID and root user group ID. You must set the appropriate file owner and group permissions to ensure consistent read and write access. For example, if you want different functions to share NAS file resources, you must use the same user and user group when you configure the NAS file system for these functions.

Remote directory and local directory

Each NAS mount target consists of a Remote Directory and a Local directory of a function. Mounting a NAS file system creates a mapping from a local directory in a Function Compute instance to a remote directory on the NAS file system.

  • Remote Directory

    A remote directory is a directory on a NAS file system. It consists of a mount target and an absolute path. The complete remote directory path is formed by concatenating the mount target and the absolute path. For example, if the mount target is xxxx-nas.aliyuncs.com and the absolute path you want to access is /workspace/document, the complete remote directory is xxxx-nas.aliyuncs.com:/workspace/document.

    Log on to the NAS console. In the file system list, click the target file system, and then click Mount Target to obtain the mount target.

  • Local directory of a function

    The local directory in the function runtime is the mount point on the local file system. Use a subdirectory of /home, /mnt, /tmp, or /data. Do not mount a NAS file system to common Linux and Unix system directories or their subdirectories, such as /bin, /opt, /var, or /dev.

Related documents

  • Function Compute supports several storage types, including File Storage NAS, Object Storage Service (OSS), temporary disk, and layers. To understand the use cases and differences between them, see Select a storage type for your function.

  • If you need to store large amounts of unstructured data such as images, videos, or documents, we recommend mounting an OSS bucket. For more information, see Configure an OSS mount.

  • You can also use Serverless Devs to mount a NAS file system. For details, see Common Serverless Devs commands.