简体   繁体   English

无法从 Google App Engine 上的 NestJS 项目访问 Google Cloud SQL 上的 PostgreSQL

[英]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 中的第一个问题,所以如果我的信息不足,请原谅。

Issue问题

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.由于我挣扎了几天,我决定在这里询问很棒的社区。

My Environment我的环境

  • Node.js: v10.19.0 Node.js: v10.19.0
  • NestJS: 6.10.5 NestJS:6.10.5
  • TypeORM类型ORM
  • PostgreSQL: 11.5.1 PostgreSQL:11.5.1

My app.yaml我的应用程序.yaml

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

Error错误

[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:

Others Operations其他业务

GAE Service Account GAE 服务帐户

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 作为参数。

eg my-awesome-project:us-central1:my-cloud-sql-instance例如 my-awesome-project:us-central1:my-cloud-sql-instance

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.

相关问题 如何允许Google App Engine访问Google Cloud PostgreSQL - How to allow Google App Engine access Google Cloud PostgreSQL Google Cloud Function 在另一个项目中访问 Cloud SQL PostgreSQL - Google Cloud Function access Cloud SQL PostgreSQL in another project 无法将 Spring Boot -Google App Engine 与 Postgresql 连接 - Cloud Sql - Cannot connect Spring Boot -Google App Engine with Postgresql - Cloud Sql 在本地并通过App Engine Flex连接到Google Cloud SQL(PostgreSQL) - Connecting to Google Cloud SQL (PostgreSQL) locally and through App Engine Flex Google Cloud App Engine与Postgresql的连接被拒绝 - google cloud app engine to postgresql connection refused Spring 启动应用程序在部署到 Google App Engine 时无法连接到 Google Cloud SQL (PostgreSQL) - Spring Boot app can't connect to Google Cloud SQL (PostgreSQL) when deploying to Google App Engine 从应用引擎实例连接到Google云SQL - Connecting to a google cloud SQL from an app engine instance Google Cloud App Engine - Django 应用程序使用 PostGreSQL 失去 SQL 连接 - Google Cloud App Engine - Django App using PostGreSQL loses SQL connection 如何从计算引擎自动将 csv 数据加载到 Google Cloud SQL(PostgreSQL 表)中 - How to load csv data into Google Cloud SQL(PostgreSQL table) automatically from compute engine Google Cloud Function 访问 Cloud SQL PostgreSQL DB 超时 - Google Cloud Function access Cloud SQL PostgreSQL DB timeout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM