2

I am trying to connect to an CloudSQL instance via Cloud Run but whenever I send a POST request the logs for the cloud run instance report:

Cloud SQL instance "INSTANCE_NAME" is not reachable. Deploy a new revision adding the Cloud SQL connection. See documentation: https://cloud.google.com/sql/docs/mysql/connect-run

and followed by

Error: connect ENOENT /cloudsql/INSTANCE_NAME at Query._callback (/app/index.js:65:35)

I have followed the documentation and added a public ip connection to my Cloud SQL instance as 0.0.0.0/0 and I added an sql connection to the instance via cloud console update command.

connections

I have also added SQL Admin and SQL Client permissions to all my service accounts and enabled the SQL Admin extension.

When I run my code locally via TCP and I am able to send a POST request as well.

if (process.env.NODE_ENV == "production") {
  const dbSocketPath = process.env.DB_SOCKET_PATH || "/cloudsql";

  pool = mysql.createPool({
    user: process.env.DB_USER,
    password: process.env.DB_PASS,
    database: process.env.DB_NAME,
    //      host:<instance-public-ip> //<- works locally
    //      port:3306
    socketPath: `${dbSocketPath}/${process.env.INSTANCE_CONNECTION_NAME}`,
  });
}

I am all out of ideas, I think the socketpath /cloudsql/ does not exist. Is there a way I can check if it exists?

7
  • What's your Cloud SQL engine and version? Commented Mar 29, 2022 at 19:21
  • 1
    Immediately remove the rule allowing 0.0.0.0/0. That is not required by Cloud Run and exposes your Cloud SQL instance to the Internet. Commented Mar 29, 2022 at 19:34
  • @guillaume My sql instance is using MySQL 5.7. Commented Mar 29, 2022 at 20:14
  • Are you using the instance name or the instance connection name? It should be in the format project:region:instance Commented Mar 30, 2022 at 1:54
  • 1
    @USER149372 Would you mind to post your solution as a formal answer to help other users that have a similar problem. Commented Mar 30, 2022 at 19:20

1 Answer 1

1

As stated in the comment by @USER149372, this issue could be resolved by:

delete the instance and service and create a new service with the SQL connection on creation.

This after ensured that the correct instance connection name is used whith the following format (as pointed out by @ kurtisvg)

project:region:instance

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

Comments

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.