当我们在std app引擎环境中使用 endpoints 时在app.yaml中跟随行,定义应用程序的起始点
- url: /_ah/spi/.*
script: main.api
但是,由于flex引擎使用“gunicorn”来定义下面给出的起始点
entrypoint: gunicorn -b :$PORT main:app
如何定义我的 Cloud endpoints main.py
作为灵活环境中谷歌应用引擎的起点?
EDIT1:
在以下建议之后this link .
我将app.yaml更新为:
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:api
service: s2
endpoints_api_service:
name: echo-api.endpoints.my-project-id.cloud.goog
config_id: my-config-id
但现在在部署时,在我的main.py文件中,我收到导入错误
ImportError: No module named endpoints
甚至将进口声明更改为
from google.appengine.ext import endpoints
没有帮助
EDIT2:
我将 endpoints 库添加到项目lib文件夹中,并添加了 appengine_config.py 文件来处理这个库,它仍然在 import endpoints
处中断 .
对于我的目录结构,请参考下图
3 回答
来自Quickstart for Endpoints on App Engine Flexible Environment的摘要(假设下面是python,如果使用其他语言选择相应的示例):
app.yaml
:endpoints_api_service:
name:echo-api.endpoints . [YOUR-PROJECT-ID] .cloud.goog
config_id:此示例中的YOUR-CONFIG-ID#2016-04-27R2 .
保存app.yaml文件 . 当您对Open API规范进行更改时,您将需要重复这些步骤并更新app.yaml文件 .
对于Endpoints Frameworks v1.0,您必须将 endpoints 模块复制到app目录中以在Flex上部署它 . 如果您're using the Cloud SDK, it'位于
/path/to/google-cloud-sdk/platform/google_appengine/lib/endpoints-1.0
.您引用的文档/链接是Google App Engine提供的可扩展服务代理,它使用可以使用普通http请求调用的OpenAPI规范 . 可以通过使用App Engine提供的Access Control来限制 endpoints 服务的条目 . 整个过程只适用于App Engine灵活环境 .
在Flex上OverView GAE endpoints
可扩展服务代理需要与我们的传统 endpoints 配置不同 .
使用gcloud service-management deploy openapi.yaml部署开放API配置
部署API后端 . gcloud service-management configs list --service = [YOUR-PROJECT-ID] .appspot.com
在app.yaml中替换ENDPOINTS-SERVICE-NAME和ENDPOINTS-CONFIG-ID,然后使用gcloud app deploy进行部署
对于App Engine标准环境用户,可以使用新版本的 endpoints (Endpoint Framework 2.0) . 目前,App Engine Flexible Environment不支持 endpoints 框架 . 如果您想使用现有代码,我建议使用migration to Endpoint Frameworks 2.0 .