Wednesday, September 26, 2018

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

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/289aead4-0c7d-4c83-b2ca-87f3cf64c8fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment