Google Clould Functions deploy: EROFS: read-only file system
Everything in the Cloud Functions runtime is read-only except for os.tmpdir()
(which is likely going to be /tmp
, but you shouldn't assume that). If you have any code (in api/user.js
for example) that attempt to write anywhere else, it'll error.
Same issue for python, but putting this for clarity. My error -
File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 753, in download_to_filename
with open(filename, "wb") as file_obj:
OSError: [Errno 30] Read-only file system: 'testFile.zip'
Get the temp directory as follows (usually /tmp
):
import tempfile
tmpdir = tempfile.gettempdir()
Googles documentation can be found here.
While Cloud Storage is the recommended solution for reading and writing files in App Engine, if your app only needs to write temporary files, you can use standard Python 3.7 methods to write files to a directory named /tmp.
All files in this directory are stored in the instance's RAM, therefore writing to /tmp takes up system memory. In addition, files in the /tmp directory are only available to the app instance that created the files. When the instance is deleted, the temporary files are deleted.