You need to enable JavaScript to run this app.
Volcano Engine Function as a Service

Volcano Engine Function as a Service

Copy page
Download PDF
Data processing
Using veFaaS to read and write the TOS mount directory
Copy page
Download PDF
Using veFaaS to read and write the TOS mount directory
Mounting a TOS Bucket on a function enables persistent data storage and sharing across multiple functions. This article introduces how to use the veFaaS to read and write the mounted TOS Bucket.​
Scenario introduction​
Mounting a TOS Bucket on a function allows persistent data storage and sharing across multiple functions. In addition, functions can access TOS like a local file system, simplifying resource access and data processing.​
Prerequisites​
  • Torch Object Storage (TOS)​
  • Volcano Engine Torch Object Storage (TOS) is activated.​
  • A TOS Bucket is created in the region where functions will be deployed. For detailed instructions, see Creating buckets.​
warning​
To better manage permissions, it is recommended to use IAM user keys with minimal authorization. Avoid using Volcano Engine root user keys or IAM user keys with excessive permissions directly.​
  • veFaaS​
  • The veFaaS is activated.​
Procedure​
Step One: Create a function and mount TOS​
  1. Log in to the veFaaS console.​
  1. In the top navigation bar, select the target region.​
  1. On the function list page, click Create function and select Create [Event function].​
  • Basic information​
  • Enter a function name and notes.​
  • Function code​
  • Runtime: Select Python.​
  • Code template: Select vefaas-python38-default.​
  • Advanced settings​
  • Enable TOS mount feature for storage configurations, and keep other parameters as default.​
  • ​
    Parameter​
    Description​
    AKSK​
    Enter Access Key ID and Secret Access Key to authorize the veFaaS to use TOS. The access key must have reading and writing permissions for TOS.​
    TOS mount​
    Add a TOS mount point. This example adds one TOS mount point.​
    • Bucket: Select the TOS Bucket to mount.​
    • Access address: Automatically obtained after selecting the Bucket.​
    • Bucket subdirectory: Select the Bucket subdirectory the function needs to access. Must start with /. This example is /docdemo.​
    • Local directory: Configure the local directory in the function operation environment. This example is /mnt/tos.​
    • Permission: This example selects reading and writing permissions, allowing the function to read and write the local directory mounted on the Bucket.​
    ​
  1. Click Create to create the function.​
Step Two: Edit code online​
This article uses the following code example to demonstrate to you how to read and write the mounted TOS Bucket.​
tip​
The code logic is for reference only. Modify the code according to your actual business scenario as needed.​
On the Code tab of the current function, click index.py file, overwrite the original content with the following code, and click Save.​
​
import json​
import os​
​
def handler(event, context):​
print(f"received new request, event content: {event}")​
​
# The local directory of the mount point. Keep consistent with the actual situation.​
mount_path = '/mnt/tos'# Read a file from the mount directory. Replace tos.txt with a file that exists in the mount directory in actual use.​
file_path = os.path.join(mount_path, 'tos.txt')​
if os.path.exists(file_path):​
with open(file_path, 'r') as file:​
content = file.read()​
print("Content of tos.txt:", content)​
else:​
print("tos.txt does not exist.")​
​
# Write a file to the mount directory.​
write_path = os.path.join(mount_path, 'output.txt')​
with open(write_path, 'w') as file:​
file.write("Hello, TOS mount!")​
print("Wrote to output.txt in TOS mount.")​
​
result = {​
'statusCode': 200,​
'headers': {​
'Content-Type': 'application/json'​
},​
'body': json.dumps({​
'message': 'Hello veFaaS TOS mount!'​
})​
}​
return result​
​
Step Three: Release the function​
Release the current code and configuration of the function online.​
  1. On the function details page, click Release in the upper right corner.​
  1. Select Latest for the function version. Keep other parameters as default.​
  1. Click OK. Wait until the function release is finished.​
Validating results​
  1. Test the function to verify whether the response result meets expectations.​
  1. On the function details page, click Test in the upper-right corner.​
  1. On the pop-up function test page, configure the Trigger type and test request.​
  • Trigger type: Select API Gateway Trigger.​
  • Test request: Keep the default.​
  1. Click Test. Wait for the test results.​
  1. View the instance logs of the function to confirm whether the expected file reading and writing is completed.​
  1. Switch to the Resource management tab.​
  1. In the Instances list, select the running instance, click Logs, and enter the instance logs page.​
  • tip​
  • When a function has multiple instances, it is recommended to check the logs of each instance to identify the one instance actually handling the request.​
  1. Log in to the TOS console and check whether the output.txt file is written under the corresponding mount directory.​
​
Last updated: 2026.08.19 14:06:07