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.
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.
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.
Check your logs for any errors during startup using:
the following cmd gcloud app logs tail -s default
or,
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With