tencent cloud

Feedback

Using CFS on SCF

Last updated: 2022-01-18 14:44:36

    Overview

    Tencent Cloud's Serverless Cloud Function (SCF) is a serverless execution environment that enables you to build and run applications without having to purchase and manage servers. Simply code in a supported language and set the execution conditions, and your code can be run on the Tencent Cloud infrastructure elastically and securely. SCF is an ideal computing platform for use cases such as real-time file processing and data processing.

    SCF is a service-level computing resource that features fast iteration and super-fast deployment. As a result, it requires the separation of storage and computing, which makes CFS, a high-performance shared storage service, the best storage solution for SCF. With only a few easy steps, your function can easily access files stored in CFS. The benefits of using CFS on SCF are as follows:

    • The execution space of functions is unlimited.
    • Multiple functions can share the same file system to share files.

    Directions

    Associating SCF with a CFS access policy

    Note:

    To use the CFS service, SCF needs permission to operate on your CFS resources.

    Follow the steps below to grant the permission to your account:

    1. Associate the SCF_QcsRole role with the QcloudCFSReadOnlyAccess policy as instructed in Modifying a Role.
      If you don't perform this operation for your currently used account, problems such as the failure to save functions and the unavailability of CFS features may occur.
    2. If the currently used account is a sub-account, please request the root account to associate the sub-account with the QcloudCFSReadOnlyAccess policy as instructed in Setting Sub-user Permissions.
      If you don't perform this operation for your currently used sub-account, problems such as the unavailability of CFS features may occur.

    Creating a VPC

    Build a VPC as instructed in Building Up an IPv4 VPC.

    Creating CFS resources

    Create a CFS file system as instructed in Creating File Systems and Mount Targets.

    Note:

    Currently, SCF allows only CFS file systems whose network type is VPC to be added as mount targets. When creating a CFS file system, please select the same VPC as that of the target function to enable communication.

    Mounting and using the CFS file system on SCF

    1. Log in to the SCF console and click Function Service in the left sidebar.
    2. On the Function Service page, select the name of the function to be configured.
    3. On the Function Configuration tab of the Function Management page, click Edit in the top-right corner.
    4. Check Enable for VPC, and select the VPC where your CFS file system resides.
    5. Check Enable for File System, and enter the following information to mount the file system, as shown below:
      • User ID and User Group ID: IDs of the user and user group in the CFS file system. SCF uses “10000” for both the user ID and user group ID by default to manipulate your CFS file system. Please set the file owner and corresponding group permission as needed and ensure that your CFS file system has the required permission. For more information, please see Managing Permissions.
      • Remote Directory: the remote directory in the CFS file system to be accessed by the function, which consists of a file system and a remote directory.
      • Local Directory: mount target of the local file system. You can use a subdirectory in the /mnt/ directory to mount the CFS file system.
      • File System ID: select the file system to be mounted in the drop-down list.
      • Mount Point ID: select the ID of the mount target corresponding to the file system in the drop-down list.
    6. Click Save at the bottom of the page to complete the configuration.
      You can edit the function code to start using the CFS file system, as shown below:
    'use strict';
    var fs = require('fs');
    exports.main_handler = async (event, context) => {
    await fs.promises.writeFile('/mnt/file.txt', JSON.stringify(event));
    return event
    }
    

    Performance test for using the CFS file system on SCF

    You can use this Demo to test how well CFS performs on SCF.

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support