1

I am getting the above error when trying to connect to a cloud sql instance that is sitting in another project. This then also throws the following error in the logs:

ENOENT /cloudsql/${process.env.INSTANCE_CONNECTION_NAME}/.s.PGSQL.5432

The connections in Cloud Run have been set up and points to the instance in the other project:

Cloud run connections

Additionally the service account used for this deployment has Cloud SQL Client permissions in both its own project and the one where the SQL instance is.

Finally the environmental variable is also set in cloud run and has the correct instance connection name.

I originally tried to get this working on an existing deployement with no luck and then also deployed it from scratch, but the same errors keep occuring.

The application is node.js based with sequelize as ORM.

Any help would be much appreciated.

10
  • One thing to make sure is that you have the Cloud SQL Admin API enabled within both Google Cloud projects. Commented Jul 6, 2022 at 17:32
  • @JackWotherspoon I had checked that too and the API is enabled in both projects Commented Jul 7, 2022 at 6:21
  • @nm_machine89 whats the cloud sql version you are using? Commented Jul 7, 2022 at 13:03
  • @nm_machine89 is the Cloud SQL instance setup for public or private IP? Commented Jul 7, 2022 at 13:03
  • @DivyaniYadav PostgreSQL 14 Commented Jul 7, 2022 at 14:16

1 Answer 1

0

I've manged to solve this, the problem was in the config.js with the connection strings.

Intially the connection string was like:

username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: '/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}',
dialect: 'postgres',
dialectOptions: {
  socketPath: '/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}'
}

It seems that Cloud Run was not able to read the INSTANCE_CONNECTION_NAME. I changed this to:

username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.INSTANCE_CONNECTION_NAME,
dialect: 'postgres',
dialectOptions: {
  socketPath: process.env.INSTANCE_CONNECTION_NAME
}

and set the INSTANCE_CONNECTION_NAME to include the /cloudsql/ portion and voila it worked.

Sign up to request clarification or add additional context in comments.

1 Comment

It's because you used single quotes instead of backquotes. You have to use backquotes to have string interpolation developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.