简体   繁体   中英

GCP Cloud Run Cloud - Cloud SQL instance "${process.env.INSTANCE_CONNECTION_NAME}" is not reachable

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM