How Does a FunctionGraph Function Read and Write an Uploaded File?
Background
A function can read files in the code directory. The working directory of a function is the upper-level directory of the handler file. Assume that you have uploaded a folder named backend. To read its test.conf file in the same level of directory as the handler file, use relative path code/backend/test.conf or use a full path (that is, the value of the RUNTIME_CODE_ROOT environment variable). To write a file (for example, to create or download a file), go to the /tmp directory or use the file system mounting feature provided by FunctionGraph.
- If containers are reclaimed, file read/written content will become invalid.
- Currently, FunctionGraph does not support instance persistence.
Typical Scenarios
- Download files stored in Object Storage Service (OBS) to the /tmp directory for processing.
- To store function execution data in OBS, create a file in the /tmp directory, write the data into the file, and then upload the file to OBS.
Obtaining Uploaded Files
Take Python as an example. If you use os.getcwd() to query the current directory, the directory will be /opt/function. However, code has actually been uploaded to /opt/function/code.
You can use either of the following methods to obtain uploaded files:
- Run the cd command to switch to /opt/function/code.
- Access the full path (value of the RUNTIME_CODE_ROOT environment variable).
You can obtain uploaded files by referring to the preceding methods when other languages are used.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot