I have a NestJs API triying to deploy to Cloud Run but it fails at the moment it tries to connect to Cloud SQL. i’m using typeORM.
This is the config to connect the DB
import { Client, ClientConfig } from 'pg';
let dbConfig: ClientConfig = {
host: process.env.DB_HOST,
port: +process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASS,
};
const client = new Client(dbConfig);
tried to pass diferent “host”
This is the error iam getting if using the Cloud SQL Connection name
Error: connectToServer: Error: getaddrinfo EAI_AGAIN project-name:us-central1:db-name
This is the error iam getting if using the Cloud SQL Public IP address
Error: connectToServer: Error: connect ETIMEDOUT xxx.xxx.xxx.xxx:5432
The Cloud Run have a service account with Cloud SQL client roles
In Cloud SQL connections i selected my SQL instance
I am explicity passing this vars in cloud run config
- DB_HOST=public ip or connection name
- DB_PORT=5432
- DB_USER=user setted at sql creation
- DB_PASS= pass setted at sql creation
- DB_NAME= db name created on cloud sql
I expect to connect to the DB as normal as i connect when iam on localhost
Jorge Obregón Pérez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.