All Products
Search
Document Center

Function Compute:Configure a NAS file system

Last Updated:Mar 24, 2026

In Function Compute scenarios where multiple applications or functions need to share access to the same dataset, such as in machine learning applications where trained models are shared among multiple inference functions, you can configure a NAS file system for the function to store this data. This enables file sharing, simplifies data management, and resolves local disk space limitations. After configuring a NAS file system for a function, your FC function can easily read from and write to NAS files just as it would with a local file system.

Prerequisites

  • Function Compute

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

    Note

    Currently, NAS mount points can only be added in a private VPC environment. Therefore, when configuring the network, you must allow the function to access resources within the VPC and configure the correct VPC to access the specified NAS file system.

  • File Storage NAS

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

Limits

  • In Function Compute, a single function in the same region can be configured with a maximum of 5 NAS mount points and 5 OSS mount points.

  • The local directories in the function's runtime environment for NAS and OSS mount points must not conflict.

Configure a NAS file system

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

  2. In the top navigation bar, select a region. On the Function page, click the target function.

  3. On the function details page, select the Configuration tab, click Advanced Settings next to Modify. In the Advanced Settings panel, find the Storage option, enable Mount NAS File System, configure it as described below, and then click Deploy.

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

    Automatic

    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.

    When you select Automatic Configuration again, the system will detect that this NAS file system already exists in the current region and will reuse it and its associated VPC configurations without creating them again. For billing details, see VPC Billing and General-purpose NAS Billing.

    Custom

    You need to manually select the NAS file system and set NAS-related parameters such as user, user group, and NAS mount point to complete the configuration.

    Key parameters are described below:

    Parameter

    Description

    Example

    NAS File System

    Select an existing NAS file system.

    To create a new NAS file system, click Create New NAS File System below to go to the File Storage Console to create one manually.

    Important

    Only NAS file systems of the NFS protocol type are supported, SMB protocol type is not supported.

    01d394****

    User, User Group

    You need to enter a custom User ID and Group ID. If you do not enter any values, the system will use the root user, i.e., UID=0 and GID=0. For more information, see NAS user and user group.

    1

    Remote Directory

    • For General-purpose NAS, this directory must start with /.

    • For Extreme NAS, this directory must start with /share.

    If the directory you configure does not exist on the remote NAS, Function Compute will automatically create it for you. The owner of the directory will be the user and group configured above, with permission level 777.

    For more information, see Remote directory.

    /

    Function Local Directory

    It is recommended to use a subdirectory of /home, /mnt, /tmp, or /data.

    Note

    Do not use common Linux and Unix system directories and their subdirectories, such as /bin, /opt, /var, or /dev, to avoid mount failures.

    For more information, see Function local directory.

    /mnt/nas

    Note
    • If you want different functions to share NAS file resources, you need to use the same user and group when configuring the NAS file system for these functions.

    • Files uploaded to NAS have the exact same permissions as local files.

Verify the NAS mount

Prepare the function code

After configuring the NAS file system, you can access the NAS file system in your function code through the path specified during mounting.

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

    This article uses a Python event function code as an example to write content to the NAS file system and read content from the 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)
            # 写入NAS文件
            content = "NAS here I come"
            os.mkdir(new_dir)
            fw = open(new_dir + file_name, "w+")
            fw.write(content)
            fw.close()
            # Showing the folder tree in NAS
            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))
            # 读取NAS文件
            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 successfully deployed, click Code on the Test Function tab.

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

    image

  2. (Optional) After writing and reading the file, you can log in to the instance to check the files in the function's local directory and confirm that the queried NAS files are consistent with the log output from the successful function execution in the previous step.

    1. On the function details page, click the Instances tab, and click Log on to Instance in the Actions column of the target instance.

      If there are no running instances, you can click Code on the Test Function tab to execute the function again and create an instance.

    2. After successfully logging into the instance, you can use commands to view the file information in the configured function's local directory. An example is as follows:

      image

Related concepts

NAS user and user group

UserID and GroupID values range from [0, 65534]. If not specified, they default to 0, representing the root user ID and root group ID, respectively. You need to set the file owner and corresponding group permissions according to your needs to ensure consistent file read and write permissions. For example, if you want different functions to share NAS file resources, you must use the same user and group when configuring the NAS file system for these functions.

Remote and local directories

The address of each NAS mount point consists of a remote directory and a function local directory. The process of mounting NAS is essentially creating a mapping from a local directory in the Function Compute instance to a remote directory on NAS.

  • Remote Directory

    The remote directory on NAS refers to a directory located in the NAS file system, composed of a mount point and an absolute path. Mount points can be added through the NAS console. The remote directory is formed by combining the mount point and the absolute path. For example, if the mount point of the NAS file system is xxxx-nas.aliyuncs.com and the absolute directory you want to access is /workspace/document, the corresponding full remote directory is xxxx-nas.aliyuncs.com:/workspace/document.

    You can log in to the NAS console, click the target file system in the file system list, and then click Mount Target to get the mount point.

  • Function Local Directory

    The local directory in the function's runtime environment refers to a mount point on the local file system. It is recommended to use subdirectories of /home, /mnt, /tmp, or /data. Do not use common Linux and Unix system directories and their subdirectories for mounting NAS, such as /bin, /opt, /var, or /dev.

Related documents

  • Function Compute supports various storage types, including File Storage NAS, Object Storage Service (OSS), temporary disk space, and layers. To understand the applicable scenarios and differences between these storage types, see Storage options.

  • If you need to store large amounts of unstructured data such as images, videos, and documents, it is recommended that you mount an OSS system. For more information, see Configure OSS.

  • You can also use Serverless Devs to mount a NAS system for a function. For details, see Common Serverless Devs Commands.