首页 文章

Flex应用引擎上的google endpoints

提问于
浏览
2

当我们在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 处中断 .

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

enter image description here

3 回答

  • 1

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

    • 配置 endpoints :

    要配置 endpoints ,请在openapi.yaml配置文件的主机字段中将YOUR-PROJECT-ID替换为您自己的项目ID:swagger:“2.0”
    信息:
    说明:“一个简单的Google Cloud Endpoints API示例 . ”
    Headers :“ endpoints 示例”
    版本:“1.0.0”
    主持人:“echo-api.endpoints.YOUR-PROJECT-ID.cloud.goog”

    • 部署您的Open API规范:

    要部署Open API规范,请运行以下gcloud命令:gcloud service-management deploy openapi.yaml
    这将创建一个名为echo-api.endpoints.YOUR-PROJECT_ID.cloud.goog的新的Cloud Endpoints服务(如果它不存在),然后将该服务的配置更新为您的Open API规范 . 该命令返回多行信息,包括类似于以下内容的行:上传服务配置[2016-04-27R2]
    “回声api.endpoints [YOUR-PROJECT-ID] .cloud.goog”
    记下服务名称和服务配置ID,它将在下一步中使用 .

    • 更新您的 app.yaml

    编辑app.yaml以反映 endpoints 配置ID并添加以下内容以在App Engine Flex上启用 endpoints API管理功能并添加服务名称和配置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 .
    保存app.yaml文件 . 当您对Open API规范进行更改时,您将需要重复这些步骤并更新app.yaml文件 .

  • 1

    对于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 .

  • 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 .

相关问题