从 Google Cloud Endpoints 连接到 Cloud SQL 时出错

问题描述

我使用 Cloud sql - postgresql 作为数据库实例在 Google App Engine 上部署了一个 Flask 应用程序 app1。 基本的 CRUD 操作按预期工作。

此外,我还有另一个烧瓶应用,app2 部署在应用引擎上,使用 firestore 作为数据库。 基本的 CRUD 操作也按预期工作。

现在,我已经开始使用 Google Cloud Endpoints 来管理上述两个应用程序的 API。 使用 firebase 的 app2 使用指定的身份验证架构按预期工作。

但是,使用 Cloud sql - postgresql 作为数据库实例的 app1 不起作用。 我收到以下错误

psycopg2.OperationalError: Could not connect to server: No such file or directory

我感觉 Google Endpoints 不允许 app1 连接到云 sql - postgresql 实例。

我应该修改 openapi.yaml 还是 app1 的 app.yaml

openapi.yaml 如下

swagger: "2.0"
info:
  title: "Testing"
  description: "Testing"
  version: "1.0.0"
host: "my-project.appspot.com"
schemes:
  - "https"
  "/testApi":
    get:
      security:
      - ApiKeyAuth: []      
      description: "testApi"
      operationId: "testApi"      
      responses:
        200:
          description: "Success."
          schema:
            type: string            
securityDeFinitions:
  ApiKeyAuth:
    type: "apiKey"
    in: "query"
    name: "key"

app.yaml 如下

service: app1
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
  python_version: 3

endpoints_api_service:
  name: my-project.appspot.com
  rollout_strategy: managed
  
automatic_scaling:
  min_num_instances: 1
  max_num_instances: 2
  cool_down_period_sec: 180
  cpu_utilization:
    target_utilization: 0.6
  target_concurrent_requests: 100  

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)