Friday, September 28, 2018

[google-cloud-sql-discuss] Re: Fails to connect to Cloud SQL when using Knex.js (direct driver works fine)

Also you should be using socketPath instead of host/port to connect to CloudSQL from cloud function, see documentation - https://cloud.google.com/functions/docs/sql

On Friday, September 28, 2018 at 5:29:39 AM UTC+2, Emerson Moraes wrote:
Hi Igor, i'm sorry to use your issue to make a question to you.

I'm trying to run postgresDemo (from node js samples) function to connect with my CloudSQL Postgres passing all needed env params. You said that if you use "pg" directly it works fine. In my case it's not working. I'm getting the following error:

{"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":5432}

Do you passed by this problem too?

Note: my App Engine Java Application is getting connection with the same params that I'm using in Cloud Function.

Thank You so much,

Emerson Leite de Moraes

quinta-feira, 27 de Setembro de 2018 às 14:36:47 UTC-3, Igor Savin escreveu:
We are trying to query Cloud SQL instances (PostgreSQL and MySQL 2nd generation) from a Cloud Function (Node.js 8).

When we create pool directly using driver (e. g. using "pg" or "mysql2"), for an example like this:


const dbConfig = {
 user
: 'username',
 password
: 'password',
 database
: 'dbName',
 socketPath
= `/cloudsql/instance_name`;
};



mysql
.createPool(dbConfig)

It works just fine. However, if we try instantiating pool using knex, e. g. like this:

const dbConfig = {
 user
: 'username',
 password
: 'password',
 database
: 'dbName',
 socketPath
= `/cloudsql/instance_name`;
};


Knex(client: 'mysql2',
connection
: dbConfig)


we get error during execution:

D functionName kkb7wsgnbixj Function execution started functionName kkb7wsgnbixj
D functionNAme kkb7wsgnbixj
Function execution took 818 ms, finished with status: 'connection error' functionName kkb7wsgnbixj


This seems to be specific to Cloud Functions/Cloud SQL, because locally knex code works just fine and it also works just fine from non-cloud-function projects as well.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/81981530-02a6-48ac-a202-21cc727a2b39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment