Google Cloud SQL Postgres Connectivity using the cloud_sql_proxy via Hosted Functions

Not applicable

I am having some issues getting my node application to connect to google cloud sql postgres from an hosted application. I have the node module working successfully in local. I am successfully able to deploy the node application as a hosted target using apigeetool but for some reason my connection to the database is not resolved using the instance connection name in my env variable.

As part of the node app the cloud_sql_proxy needs to be started in the docker image that runs the node application in the app engine. Looks like this command fails when the application is deployed. I am able to connect to the database using the public ip but would like to know if the instance connection using the clould_sql_proxy would be made available in the docker image of the hosted app.

I followed the following documentation for Cloudsql Postgres connectivity using node.js https://cloud.google.com/appengine/docs/standard/nodejs/using-cloud-sql-postgres

0 8 1,319
8 REPLIES 8

Can you provide more details? How exactly have you tried following that documentation? I need to know what you've put into your app.yaml (if anything), etc. Anything related to establishing a connection to your CLoudSQL.

Attached app.yaml, config.json and server.js. Followed apigee documentation for app.yaml. Note using the public ip of the database I was able to make my app work.

hosted.zip

That's expected, since your CloudSQL is in your GCP project and not the one your Hosted Target runs in. Also, the "app.yaml" for Hosted Targets IS NOT the same as the "app.yaml" for GAE.

Does it mean that we can only use ip based connectivity with whitelisting over SSL?

It means that since your CloudSQL instance is not running in the same GCP project as your Hosted Target GAE instance, you need to use whatever means necessary but ultimately that is up to you. Accessing the instance via IP instead of convention is a must but how you secure things is up to you.

Thanks. Will proceed with this and remove the cloud_sql_proxy dependency from the node.js app.

The Google cloud is not working in my case because I am not being able to log in to the Google account and I also forgot the password of the account. I need to recover Gmail password to have the access of the cloud.

As i know cloud_sql proxy is not available in hosted target by default. However you could :

  1. Use Public IP address with SSL as described here
  2. Have not tried this. It could be possible to package cloud_sql binary in hosted target and then use Child Process NodeJs feature to start cloud_sql proxy in child process on NodeJs code startup.