当我们在 std app engine 环境中使用端点时 app.yaml 中的以下几行定义了应用程序的起点
- url: /_ah/spi/.*
script: main.api
但由于 Flex 引擎使用“gunicorn”来定义起始点,如下所示
entrypoint: gunicorn -b :$PORT main:app
应如何将我的云端点的 main.py
定义为 Flex 环境中 Google 应用引擎的起点?
编辑1:
在 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
没有帮助
编辑2:
我将端点库添加到项目 lib 文件夹中,并添加了 appengine_config.py 文件来处理该库,但它仍然在导入端点
处中断。
对于我的目录结构,请参阅下图
最佳答案
来自 Quickstart for Endpoints on App Engine Flexible Environment 的摘要(假设下面是 python,如果使用其他语言,请选择相应的示例):
- 配置端点:
To configure Endpoints, replace
YOUR-PROJECT-ID
with your own project ID in theopenapi.yaml
configuration file's host field:swagger: "2.0" info: description: "A simple Google Cloud Endpoints API example." title: "Endpoints Example" version: "1.0.0" host: "echo-api.endpoints.YOUR-PROJECT-ID.cloud.goog"
- 部署您的开放 API 规范:
To deploy your Open API specification, run the following
gcloud
command:gcloud service-management deploy openapi.yaml
This will create a new Cloud Endpoints service with the name
echo-api.endpoints.YOUR-PROJECT_ID.cloud.goog
if it does not exist, and then update that service's configuration to your Open API specification.The command returns several lines of information, including a line similar to the following:
Service Configuration [2016-04-27R2] uploaded for service "echo-api.endpoints.[YOUR-PROJECT-ID].cloud.goog"
Make a note of the service name and the service configuration ID, it is used in the next step.
- 更新您的
app.yaml
:
Edit
app.yaml
to reflect the Endpoints configuration ID and add the following to enable Endpoints API Management features on App Engine Flex and add the service name and configuration ID:beta_settings: use_endpoints_api_management: true endpoints_api_service: name: echo-api.endpoints.[YOUR-PROJECT-ID].cloud.goog config_id: YOUR-CONFIG-ID # 2016-04-27R2 in this example.
Save the
app.yaml
file. You will need to repeat these steps and update theapp.yaml
file when you make changes to your Open API specification.
关于google-app-engine - Flex 应用程序引擎上的 Google 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41384274/