在App Engine应用程序中,有没有办法确定运行GAE(App Engine)实例的项目ID?
我想在运行App Engine实例的同一个项目中访问一个大的查询表。如果可能的话,我宁愿不硬编码或将其包含在另一个配置文件中。
编辑:忘了提到这是来自Python
您可以从环境变量中获取大量信息:
import os
print os.getenv('APPLICATION_ID')
print os.getenv('CURRENT_VERSION_ID')
print os.environ
这是“官方”的方式:
from google.appengine.api import app_identity
GAE_APP_ID = app_identity.get_application_id()
在这里查看更多:https://developers.google.com/appengine/docs/python/appidentity/
我还添加了一个应用程序版本,以防您需要它。
import com.google.appengine.api.utils.SystemProperty;
String appId = SystemProperty.applicationId.get();
String appVersion = SystemProperty.applicationVersion.get();
我在2019年使用Python3尝试了其他方法。据我所知,这些方法适用于Python2(也适用于Java)。
我能够在Python3中使用以下方法完成此任务:
import os
app_id = os.getenv('GAE_APPLICATION')
print(app_id)
project_id = os.getenv('GOOGLE_CLOUD_PROJECT')
print(project_id)
来源:https://cloud.google.com/appengine/docs/standard/python3/runtime