google-app-engine - Flex 应用程序引擎上的 Google 端点

标签 google-app-engine google-cloud-platform google-cloud-endpoints google-managed-vm

当我们在 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 文件来处理该库,但它仍然在导入端点处中断。

对于我的目录结构,请参阅下图

enter image description here

最佳答案

来自 Quickstart for Endpoints on App Engine Flexible Environment 的摘要(假设下面是 python,如果使用其他语言,请选择相应的示例):

  • 配置端点:

To configure Endpoints, replace YOUR-PROJECT-ID with your own project ID in the openapi.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 the app.yaml file when you make changes to your Open API specification.

关于google-app-engine - Flex 应用程序引擎上的 Google 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41384274/

相关文章:

android - 将 firebase 身份验证与谷歌应用引擎云端点集成

java - AppEngine 响应时间差异

go - 如何使用个人(gcloud)凭据发布到PubSub

aws-lambda - 将路径参数传递给 Google 的 Cloud Function 端点

ios - Google Cloud Endpoints 生成的 iOS 客户端无法正常工作

python - 如何使用 Google Service 验证 Docker 容器

google-app-engine - 启用内存缓存后,NDB 不会为异步获取返回相同的实例

android - 找不到所选的向导

python - 确定我的 App Engine 代码在哪个项目 ID 上运行

python - Tensorflow - 无法在 Estimator 中使用带有 MirroredStrategy 分布的 BasicLSTMCell