I'm not having any success connecting to Cloud SQL from my Node-JS app hosted on App-Engine, when I deploy via gcloud app deploy
After deploying, it throws error Error: connect ENOENT /cloudsql/<INSTANCE_CONNECTION_NAME> at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
var config = {
user: 'my_username',
database: 'test_db',
password: 'example_pass'
};
if (process.env.DB_INSTANCE_NAME && process.env.NODE_ENV === 'production') {
// Executing remotely
config.socketPath = "/cloudsql/<INSTANCE_CONNECTION_NAME>"
} else {
// Local development - add IP address to SQL access
config.host = 'XX.XX.XXX.XX';
}
let pool;
const createPool = async () => {
pool = await mysql.createPool(config);
pool.query('SELECT * FROM test_db.test_table', function (error, results, fields) {
if (error) throw error;
console.log('The result is: ', results);
});
};
createPool();
My app.yaml looks like this :
# [START app_yaml]
runtime: nodejs
beta_settings:
cloud_sql_instances: <INSTANCE_CONNECTION_NAME>
env: flex
# [END app_yaml]
The App Engine and the Cloud SQL db are both within the same project. I've been through the steps listed here many times : https://cloud.google.com/sql/docs/mysql/connect-app-engine
I can connect locally by whitelisting my ip address in the SQL Connections tab no problems.
Cloud SQL Client(which is the preferred one)?/cloudsql/CloudSQLInstanceName:Location:root