Jonathan Lin
Jonathan Lin

Reputation: 20714

Can I connect from Cloud Run to a Postgres instance hosted in Compute Engine? (not Cloud SQL)

I wish to connect Cloud Run to a Postgres database running in port 5432 in Compute Engine (not Cloud SQL). I assume from the documentation that this cannot be done. Is this really the case?

Upvotes: 0

Views: 600

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 75910

All depend how do you want to reach your database.

  • If you want (can) reach them from internet, simply create a connection between the compute engine public IP in your Cloud Run container. Don't forget to open the port 5432 for 0.0.0.0/0 IP in firewall rules. You understand that it's not the most secure...
  • If you want to reach privately your compute engine, I mean by using the private IP of the compute engine and passing by your VPC, you can't today with Cloud Run. Serverless VPC Connector should come in 2020, but until this release, you can't.

Note: In both case, don't forget to set up your connexion pool equal to the concurrency param to save/preserve your database connexion. On the same concern, you can set up a max instance limit to not use too many connexion to your database.

Upvotes: 5

Related Questions