Tuesday, October 2, 2018

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

Hello Emerson,


My colleague already answered you in your thread about this issue you are having connecting to your Cloud SQL instance.


On Friday, September 28, 2018 at 2:15:39 PM UTC-4, Emerson Moraes wrote:
Thank You so much for the answer. The functions is using the default AppEngine SA. And this account has Editor role.

I'm using socketPath instead of ip too. i have the following params (omitting only user and password here):
max: 1, user: 'username', password: 'password', database: 'appengine_helloworld_db', socketPath: '/cloudsql/hello-world-4736435:southamerica-east1:hello-world-postgis-sp'

I tried to do the connection after adding client Cloud SQL role to the SA, but I'm having the same issue. When you made this connection, which were the roles of SA?

Thank You.

sexta-feira, 28 de Setembro de 2018 às 14:49:50 UTC-3, Igor Savin escreveu:
Hi Emerson!

We've had exactly same problem: check and double-check that you are using the SA that you think you are using for the connection and that it has the correct permissions.

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/ef244bbb-97e1-4026-a298-00a4cee10376%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment