Home > Software engineering >  Can I save files in a serverless server?
Can I save files in a serverless server?

Time:11-07

For instance, if I do something like

f = open("demofile.txt", "w")
f.write("test content")
f.close()

in a serverless environment like Google Cloud Run or Anthos (assume this is part of a web app), will demofile.txt exist permanently, and will I always be able to access it through f.read()?

CodePudding user response:

Your question is strange but I will try to answer it.

You can write a file in serverless Product, such as Cloud Run, Cloud Functions and App Engine. The /tmp dir is writable. BUT it's an in memory file system. That means you can write and access your data from your instance (and not from the other instances) and the file persist up to the end of the instance. In addition, the file take space in the allocated memory. So, the storage limit is the memory size of your instance.

With Cloud Run, there is a new previous feature (released publicly only few days ago) that allows you to use a 2nd gen runtime and to use network file system(Google Cloud Storage with GCSFuse, or Filestore). It's "external storage" but viewed as local directory from your app.


A last point on Anthos (because you mentioned it in your question): Anthos is a suite of products that allows to manage from Google Cloud console, resources (mainly Kubernetes Clusters) running out of Google Cloud. There is a version of Cloud Run for Anthos, but Anthos isn't a serverless product itself.

  • Related