Error connecting to Cloud SQL from App Engine deployed Node.js app

21 views Asked by At

I have a Node.js backend application using Express and Sequelize, deployed on Google App Engine, and connected to a Google Cloud SQL database (MySQL). The application works fine locally when I test the API to add data in Cloud SQL Database, but after deploying to App Engine, I'm getting a SequelizeConnectionError with the message 'connect ETIMEDOUT'. This happens when I try to test CRUD operations against the Cloud SQL database from the deployed app.

Error logs screenshots

Postman error response

How can I troubleshoot and resolve this connection error when connecting to a Cloud SQL database from a Node.js app deployed on Google App Engine?

--- More ---

  • The database connection configuration in dbconfig.js is correct and works locally.
  • The error suggests a timeout issue, but I'm not sure what might be causing it in the deployed environment.
  • I've tried deploying with different Node.js runtime versions on App Engine but still encounter the same error.
  • All of the connection errors happen only when I test the API with the hosted url

Below is the code related to the database connection: [dbconfig.js] dbconfig.js

[models/index.js] models/index.js

[app.yaml]

runtime: nodejs18  # Node Version
entrypoint: node app.js

[Authorized Networks in Cloud SQL] Cloud SQL Screenshot

[IAM] Cloud Permissions in IAM

0

There are 0 answers