[英]Cant Access PostgreSQL on Google Cloud SQL from NestJS project on Google App Engine
This is my first question in Stack Overflow so please excuse me when my information is lack.这是我在 Stack Overflow 中的第一个问题,所以如果我的信息不足,请原谅。
I am struggling to connect PostgreSQL on CloudSQL from NestJS on Google App Engine.我正在努力从 Google App Engine 上的 NestJS 连接 CloudSQL 上的 PostgreSQL。 When I try to use the application in local environment the program works but when it comes to production in Google App Engine then it does not work.
当我尝试在本地环境中使用该应用程序时,该程序可以运行,但是当涉及到 Google App Engine 中的生产时,它就不起作用了。
Since i struggled days, I decided to ask awesome community here.由于我挣扎了几天,我决定在这里询问很棒的社区。
runtime: nodejs10
env: standard
default_expiration: "4d 5h"
env_variables:
DATABASE_HOST: < public IP for Cloud SQL instance >
DATABASE_USERNAME: username
DATABASE_PASSWORD: password
DATABASE_NAME: databasename
INSTANCE_CONNECTION_NAME: "PROJECT_ID:REGION:INSTANCE_ID:DATABASE_NAME"
handlers:
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
[Nest] 18 - 02/27/2020, 8:25:46 AM [TypeOrmModule] Unable to connect to the database. Retrying (3)... +34816ms
2020-02-27 08:25:46 default[20200227t163916] Error: connect ETIMEDOUT 34.84.188.209:5432 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:
Also I added the Cloud SQL Client authority my GAE Service account (something like this service-PROJECT_ID@gae-api-prod.google.com.iam.gserviceaccount.com).我还添加了 Cloud SQL 客户端权限我的 GAE 服务帐户(类似于这个 service-PROJECT_ID@gae-api-prod.google.com.iam.gserviceaccount.com)。
I also added package.json as written in below:我还添加了 package.json,如下所示:
extra: {
socketPath: `/cloudsql/<INSTANCE_CONNECTION_NAME>/`,
},
In the typeorm options, I added extra socketpath.在 typeorm 选项中,我添加了额外的 socketpath。
extra: { socketPath: `/cloudsql/<INSTANCE_CONNECTION_NAME>/`, },
I do not understand if this option should be set or not (I have tried both).
socketPath: `/cloudsql/<INSTANCE_CONNECTION_NAME>/.s.PGSQL.5432 or socketPath: `/cloudsql/<INSTANCE_CONNECTION_NAME>
According to the example provided in GitHub根据GitHub中提供的示例
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/cloudsql_postgresql/app.flexible.yaml https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/cloudsql_postgresql/app.flexible.yaml
The INSTANCE_CONNECTION_NAME environment variable does not include the DATABASE_NAME as a parameter. INSTANCE_CONNECTION_NAME 环境变量不包括 DATABASE_NAME 作为参数。
Maybe this could be causing that the name of the instance is not being resolved for the Proxy.也许这可能导致代理没有解析实例的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.