简体   繁体   中英

Setting environment variables in Google Cloud Platform using Cloud Functions

I'm following the guide here and can't seem to get my Python app (which is deployed fine on GCP) to read the environment variables I've created in Cloud Functions.

The REST endpoint for the function returns the environment variables fine as I've coded up the Python method in the function to just do os.environ.get() on a request parameter that is passed in. However, in my actual deployed application, I don't want to do a REST GET call every time I need an environment variable. I would expect using os.environ.get() in my application would be enough, but that returns blank.

How does one go about retrieving environment variables on GCP with just a simple os.environ.get() or do I really have to make a call to an endpoint every time?

I have been struggling with this for some time. The only solution I have found to set environment variables for the whole app is to define them in app.yaml . See the env_variables section here .

But then you cannot commit app.yaml to any version control repository if you don't want people to see the environment variables. You could add it to .gitignore . There are more secure ways to handle secrets storage if these variables contain sensitive data. If you need more robust security, you might find some inspiration here .

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