Configuring Disk Mounting¶
Introduction¶
FunctionGraph allows you to mount file systems to your functions. Multiple functions can share the same file system. This greatly expands the function execution and storage space compared with the temporary disk space allocated to a function.
Scenarios¶
FunctionGraph supports the following types of file systems:
SFS Turbo
SFS Turbo supports the following storage classes: Standard (500 GB-32 TB), Standard-Enhanced (10 TB-320 TB), Performance (500 GB-32 TB), and Performance-Enhanced (10 TB-320 TB). SFS Turbo is expandable to 320 TB, and provides fully hosted shared file storage. It features high availability and durability, and supports massive quantities of small files and applications requiring low latency and high input/output operations per second (IOPS). SFS Turbo is suitable for high-performance websites, log storage, compression and decompression, DevOps, enterprise offices, and containerized applications. For details, see SFS Service Overview.
ECS
A directory on an ECS is specified as a shared file system (see Mounting an ECS Shared Directory) by using the network file system (NFS) service. The directory can then be mounted to a function in the same VPC as the ECS so that the function can read and write data in the directory. ECS file systems make it possible for dynamic expansion of compute resources. This type of file system is suitable for low service demand scenarios.
Benefits from using these file systems:
The function execution space can be greatly expanded comparing with /tmp.
A file system can be shared by multiple functions.
ECS compute resources can be dynamically expanded and existing ECS storage capability can be used to achieve stronger computing performance.
Note
You can write temporary files in the /tmp directory. The total size of these files cannot exceed 10,240 MB.
Creating an Agency¶
Before adding file systems to a function, specify an agency with permissions for accessing the file system services for the function.
There is a limit on the maximum number of agencies you can create, and cloud service agencies cannot be modified. Therefore, you are advised to create an agency with high-level permissions, for example, Tenant Administrator, to allow a function to access all resources in the selected region. For more information, see Configuring Agency Permissions.
Mounting an SFS Turbo File System¶
Setting an Agency
Before mounting an SFS Turbo file system to a function, specify an agency that has been granted SFS Administrator and VPC Administrator permissions for the function. If no agencies are available, create one in IAM.
Configuring VPC Access
An SFS Turbo file system is accessible only in the VPC where it has been created. Before mounting such a file system to a function, enable VPC access for the function.
On the SFS console, obtain the information about the VPC and subnet where a file system is to be mounted to your function. For details, see File System Management.
Enable VPC access by referring to Configuring the Network and enter the VPC and subnet obtained in 1.
Mounting an SFS Turbo File System
SFS Turbo file systems can be mounted in the same way as SFS file systems. Select a file system and set the access path.
Follow-up Operations¶
A function can read and write data in an access path in the same way as in the mounted file system.
Function logs can be persisted by configuring the log path as a subdirectory in the access path.
The following uses SFS Turbo and template Web-Server-Access-Log-Statistics as an example to describe how to analyze logs of servers running on the cloud.
Log in to the FunctionGraph console. In the navigation pane, choose Templates.
In the upper right corner of the Templates page, enter Web-Server-Access-Log-Statistics in the search box and press Enter.
In the search result, click Configure. The configuration page is displayed, as shown in Figure 2. Set the parameters as follows:
Figure 2 Function template¶
Region: Select the same region as the created VPC and file system. For details about how to create a VPC and file system, see Configuring the Network and Creating a File System.
Project: Use default.
Function Name: Enter a custom name.
Agency: Select an agency with the file system, VPC, and APIG permissions. For details about how to create an agency, see Configuring Agency Permissions.
Enterprise Project: Select an enterprise project as required.
Environment Variables: access_log_path indicates the log file address. Set this parameter to /home/test/access_log.log.
Note
To specify file paths in the file system, use absolute paths starting with a slash (/). However, if no file system is mounted, you can skip adding the slash (/) and simply set the parameter to code/access_log.log.
Trigger Type: The default value is API Gateway (APIG). For details about how to configure APIG, see Using an APIG (Dedicated) Trigger.
API Name: Enter a custom name.
API Group: Select a group based on the actual service.
Environment: Select RELEASE.
Security Authentication: Select None.
Protocol and Timeout (ms): Retain the default values.
After parameter configuration is complete, click Create Function.
On the function details page, click the Code tab, add the following code to the index.py file, and click Deploy.
import shutil
shutil.copyfile('/opt/function/code/access_log.log', '/home/test/access_log.log')
Figure 3 Adding code¶
In addition, add the public dependency Jinja2-2.10. For details, see How Do I Add a Dependency to a Function?.
Note
If no file system is mounted, you do not need to add the preceding code.
On the function details page, choose Configuration > Network and enable VPC Access. Set VPC and Subnet to the created VPC and subnet, and click Save.
Figure 4 VPC access¶
Choose Disk Mounting, click Mount File System, and select SFS Turbo.
File System: Select an existing SFS Turbo file system.
Access Path: Set this parameter to /home/test.
Click the Code tab, select Configure Test Event, create a Blank Template, and click Create.
Figure 5 Configuring a test event¶
Select the created test event and click Test.
Figure 6 Test result¶
Choose Configuration > Triggers, copy the URL of the APIG trigger, and open the URL using a browser.
Figure 7 Copying the URL¶
Figure 8 Results display¶