Tencent Cloud 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:
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:
Associate the SCF_QcsRole
role with the QcloudCFSReadOnlyAccess
policy as instructed in Modifying Role. The result of a successful association is shown below:
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.
If the currently used account is a sub-account, request the root account to associate the sub-account with the QcloudCFSReadOnlyAccess
policy as instructed in Setting Sub-user Permissions. The result of a successful association is shown below:
If you don't perform this operation for your currently used sub-account, problems such as the unavailability of CFS features may occur.
Build a VPC as instructed in Building Up an IPv4 VPC.
Create a CFS file system as instructed in Creating File Systems and Mount Targets.
Note:Currently, SCF allows only CFS file systems with network type being VPC to be added as mount targets. When creating a CFS file system, select the same VPC as that of the target function to enable communication.
Log in to the SCF console and select Functions on the left sidebar.
On the Function Service page, select the name of the function to be configured.
On the Function configuration tab of the Function management page, click Edit in the top-right corner.
Check Enable for VPC and select the VPC where your CFS file system resides.
Check Enable for File system and enter the following information to mount the file system.
/mnt/
directory to mount the CFS file system.'use strict';
var fs = require('fs');
exports.main_handler = async (event, context) => {
await fs.promises.writeFile('/mnt/myfolder/filel.txt', JSON.stringify(event));
return event;
};
You can use this demo to test how well CFS performs on SCF.
Was this page helpful?