google-app-engine - 将 Google App Engine Flexible 中的简单节点应用程序连接到 Google Cloud SQL
问题描述
我使用 postGraphile 作为 GraphQL 服务器 - 在本地工作得很好。
试图将其推送到 App Engine 实例中。
我一生都无法弄清楚如何让 App Engine 连接到 Cloud SQL。我可以从我的计算机直接连接到 Cloud SQL(我被列入白名单),我什至尝试在列出应用引擎实例的 IP 时无效
这是我的app.yaml设置:
# per google's instructions, I'vd added the instance here, and now added a tcp port
beta_settings:
cloud_sql_instances: webstr-dev-237715:us-central1:webstr-dev=tcp:5432
# [START runtime]
runtime: nodejs
env: flex
threadsafe: yes
service: wgraphile
在我的package.json中,我使用连接参数运行 postgragphile。如果我运行此连接字符串:
postgraphile -o -c postgres://webstr:[SECRET]@localhost:5432/str_dev
我收到连接被拒绝错误:
A serious error occurred when building the initial schema. Exiting because `retryOnInitFail` is not set. Error details:
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
如果我用这个连接字符串运行它:
postgraphile -o -c postgres://webstr:[SECRET]@172.17.0.1:5432/str_dev
我收到此连接重置错误:
Postgres connection: postgres://webstr:[SECRET]@172.17.0.1/str_dev
‣ Postgres schema(s): public
A serious error occurred when building the initial schema. Exiting because `retryOnInitFail` is not set. Error details:
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
我也尝试过使用带有直接 IP 的 unix 套接字连接字符串,例如:
postgres://webstr:[SECRET]@35.202.32.69:5432/str_dev?unix_sock=/cloudsql/<cloud_sql_instance_name>/.s.PGSQL.5432
帮助?
解决方案
您似乎正在使用 App Engine Flex。如果您查看“从 App Engine 连接”页面,则需要检查以下内容:
- 您需要确保已启用 Cloud SQL Admin API
- 您需要确保 App Engine 服务帐号(默认为
[YOUR_PROJECT_NUMBER]@gae-api-prod.google.com.iam.gserviceaccount.com
)具有Cloud SQL Client
IAM 权限
然后,您app.yml
需要以下内容(看起来就像您正在做的那样):
beta_settings:
cloud_sql_instances: <INSTANCE_CONNECTION_NAME>=tcp:<PORT>
最后,完成此操作后,您应该可以在172.17.0.1:<PORT>
.
推荐阅读
- ajax - 如何在这个 wordpress 循环中添加加载更多按钮 ajax 按钮?
- c# - 相同表/类的 SQL 表设计
- c# - C# 为 ASP.NET Core 使用 System.Data.DataSet?
- django - IIS 上 django 中 POST 请求的状态 500
- c# - EF 6.0 未从具有多个 DBcontexts 的数据库生成的值返回 PK 键值
- jenkins - 如何使用 ${currentBuild.result} 表示“SUCCESS”而不是“null”
- javascript - 用于选择产品尺寸或颜色的类似电子商务的功能
- angular - 获取所有数据后显示表格(ag网格)
- android - “远程调试 JS”在做什么?
- three.js - 如何将 Blender 3D 模型导入到 three.js