简体   繁体   中英

Is there a way to make a folder in /tmp while using google cloud functions?

I needed to create two folders within /tmp folder in Google Cloud functions. I am using a library which requires the files to be in that format (they can't just all be in /tmp ).

I tried this - os.makedirs('tmp/test') but that gave the following error:

Function failed on loading user code. Error message: [Errno 30] Read-only file system: 'tmp'
Detailed stack trace:
Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v1.py", line 315, in check_or_load_user_function
_function_handler.load_user_function()
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v1.py", line 190, in load_user_function
spec.loader.exec_module(main_module)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/user_code/main.py", line 3, in <module>
os.makedirs('tmp/test')
File "/env/lib/python3.7/os.py", line 213, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/env/lib/python3.7/os.py", line 223, in makedirs
mkdir(name, mode)
OSError: [Errno 30] Read-only file system: 'tmp'

Any way I can solve this?

Using os.makedirs('tmp/test') will attempt to create a directory at /user_code/tmp/test , which is not writeable.

You'll want to use a leading slash to ensure that you're creating the directory at /tmp/test instead, which is the only writeable part of the filesystem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM