2
votes

I've successfully deployed my app to Google App Engine. My database is up and running on Cloud SQL. I'm able to connect to the database no problems from my local machine by whitelisitng my dev machine's IP on the authorised networks in cloud SQL. However when I deploy to Production, I'm getting:

Error: connect ENOENT /cloudsql/<my project id>:asia-south1:<my database instance name>

My app.yaml file looks like this:

runtime: nodejs  
env: flex

manual_scaling:  
  instances: 1
resources:  
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

env_variables:
  ST_ENV: 'Production' //Used to set the app listening on the below port
  ST_PORT: '8080'
  SQL_USER: '<username>'
  SQL_PASSWORD: '<password>'
  SQL_DATABASE: '<databasename>'
  INSTANCE_CONNECTION_NAME: '/cloudsql/<my project id>:asia-south1:<my database instance name>'

  beta_settings:
  cloud_sql_instances: '<my project id>:asia-south1:<my database instance name>'

My config file looks like this:

database: {             
            connectionLimit: 10,
            // host     : process.env.INSTANCE_CONNECTION_NAME,
            socketPath: process.env.INSTANCE_CONNECTION_NAME,
            user     : process.env.SQL_USER,  
            password : process.env.SQL_PASSWORD,  
            database : process.env.SQL_DATABASE,
            multipleStatements : true

        }

And I'm creating a connection pool (I've simplified the code for this example):

var db = config.production.database;
var pool = mysql.createPool(db);

I've been able to successfully connect from my local machine through the local cloud_sql_proxy.

I've tried using the IP of the Cloud SQL instance as the host, but that gave me the below error:

Error: connect ECONNREFUSED 127.0.0.1:3306'

I also tried specifying the host as 0.0.0.0 and port 3306 and got:

Error: connect ECONNREFUSED 0.0.0.0:3306'

Edit: both the Cloud SQL and the Cloud SQL Admin APIs are enabled:

enter image description here

It's like when pushing to production the app engine is trying to use a non existent proxy. Can anyone help?

1
Have you enabled the Cloud SQL API in the console? - Christopher P
Yep. I've editing my question to include screengrabs. - Jim Jimson
In your env_variables, try removing '/cloudsql/' from the front of the INSTANCE_CONNECTION_NAME variable - Christopher P
I installed (maybe this was stupid) the proxy on my app engine instance, and now all the errors are coming through my app engine logs. I removed the /cloudsql/ and both with and without am receiving: textPayload: "Error: connect ECONNREFUSED 127.0.0.1:3306 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14) - Jim Jimson
That isn't necessary. I recommend trying to get the server.js example provided in the samples working and then make incremental adjustments - Christopher P

1 Answers

0
votes

Take a look at the specific instructions for connecting from the Node.js runtime on App Engine Flexible. You can configure the connection using the instance connection name and some other environmental variables. It's not necessary to provide a host name or install the SQL proxy on your instance. Attempting to connect to the public IP of the Cloud SQL instance won't work from App Engine.