Owain
Owain

Reputation: 19

Cloud SQL with Firebase Functions V2

I'm receiving connect ENOENT /cloudsql/<proj>:us-west1:<instance>/.s.PGSQL.5432 When connecting to a Cloud SQL instance of PostgreSQL 15 from a Firebase V2 Callable function. I've looked everywhere and even reluctantly used ChatGPT but I cannot seem to fix the issue.

  1. I have checked my connection config (with the values substituted out)
export const createUnixSocketPool = (config: DatabaseConfig) => {
  return knex({
    client: "pg",
    connection: {
      user: config.user,
      password: config.password,
      database: "default",
      host: "/cloudsql/<proj-id>:us-west1:<instance-name>",
    },
    pool: { min: 0, max: 1 },
  });
};
  1. [email protected] has the appropriate Client role for Cloud SQL.
  2. Cloud SQL Admin API is enabled.

Upvotes: 0

Views: 130

Answers (2)

jhenya-d
jhenya-d

Reputation: 399

View function in Cloud Run And in edit mode select Cloud SQL connections

enter image description here

enter image description here

Upvotes: 0

guillaume blaquiere
guillaume blaquiere

Reputation: 75950

Your code configuration looks good, but the service configuration is not. You must tell to the service to open a connection with your Cloud SQL database, and then to open a unix socket for your code

I didn't find anywhere how to set up a Cloud SQL connection for Firebase Functions V2. The most appropriate documentation page is on Cloud Functions.

Upvotes: 2

Related Questions