Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ENOENT when connecting to Google Cloud SQL from App Engine

I'm trying to deploy my Node.js app on Google App Engine and it deployed fine, but it can't connect to Google Cloud SQL for some reason. Here's what it throws:

Error: connect ENOENT /cloudsql/my-project-id:asia-east1:my-sql-instance

Here's how I configured the connection:

if (process.env.INSTANCE_CONNECTION_NAME) {
     exports.mysqlConfig = {
         user: process.env.GCLOUD_SQL_USERNAME,
         password: process.env.GCLOUD_SQL_PASSWORD,
         socketPath: '/cloudsql/' + process.env.INSTANCE_CONNECTION_NAME
     }
} else {
    // Use settings for localhost
}

I'm using node-mysql module to connect to the database.

The App Engine and Cloud SQL are already in the same project. My theory is that the App Engine and the Cloud SQL has to be in the same project and same region, but I'm not sure.

like image 998
starleaf1 Avatar asked Feb 01 '17 02:02

starleaf1


People also ask

What is the difference between APP engine standard and flexible?

The standard environment can scale from zero instances up to thousands very quickly. In contrast, the flexible environment must have at least one instance running for each active version and can take longer to scale up in response to traffic. Standard environment uses a custom-designed autoscaling algorithm.

How do I connect Google Cloud to SQL?

In the Google Cloud console, go to the Cloud SQL Instances page. To open the Overview page of an instance, click the instance name. Select Connections from the SQL navigation menu. In the Authorized networks section, click Add network and enter the IP address of the machine where the client is installed.


1 Answers

Check your logs for any errors during startup using:

  1. the following cmd gcloud app logs tail -s default or,

  2. with the log viewer https://console.cloud.google.com/logs/viewer

Chances are that you have not enabled the Cloud SQL API for your project: https://console.developers.google.com/apis/api/sqladmin/overview

like image 82
jermel Avatar answered Sep 24 '22 04:09

jermel