简体   繁体   中英

Setting Google Cloud Environment Variables for Flask

Each time I set environment variables for my Flask app on the google cloud console they are deleted when I turn off the machine. How can I make environment variables such as FLASK_APP persistent, even after shutting down?

If you are using Cloud Shell, There is no way to set permanent Environmental Variables as Cloud Shell Instances are ephemeral. https://cloud.google.com/shell/docs/how-cloud-shell-works

If you are using Compute Engine, Cloud Functions, Cloud Run, App Engine, or most GCP Products, Environmental variables can be set in the Cloud Console when creating the instance.

Once the environmental variable is set, you can call it anytime within the VM or within the code. Here is an example of calling a ENVVAR via code(python). As long as the ENVVAR is not changed, it will last the lifetime of the instance.

import os
os.environ.get("varname") 

Hope this helps! Comment to this if you would like more explanation.

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