使用Cloud Functions在Google Cloud Platform中设置环境变量 [英] Setting environment variables in Google Cloud Platform using Cloud Functions

查看:97
本文介绍了使用Cloud Functions在Google Cloud Platform中设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵守此处的指南,似乎无法获取我的Python应用程序(可以在GCP上很好地部署)来读取我在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.

该函数的REST端点返回的环境变量很好,因为我已经在该函数中编写了Python方法,以便仅对传入的请求参数执行os.environ.get().但是,在我实际部署的应用程序中,不想在每次需要环境变量时都进行REST GET调用.我希望在我的应用程序中使用os.environ.get()就足够了,但是返回空白.

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.

如何只用一个简单的os.environ.get()在GCP上检索环境变量?或者我真的必须每次都调用一个端点吗?

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?

推荐答案

我已经为此苦苦挣扎了一段时间.我发现为整个应用程序设置环境变量的唯一解决方案是在app.yaml中定义它们.请参见此处.

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.

但是,如果您不希望人们看到环境变量,则不能将app.yaml提交到任何版本控制存储库.您可以将其添加到.gitignore.如果这些变量包含敏感数据,则存在更安全的方式来处理机密存储.如果您需要更强大的安全性,可以在此处.

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.

这篇关于使用Cloud Functions在Google Cloud Platform中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆