I have a Google Cloud Run service that needs to access data stored in a Google Cloud SQL instance using PostgreSQL. I've followed the general steps of creating both the Cloud Run service and the Cloud SQL instance, but I'm having trouble establishing the connection between them.
I've tried using the following methods:
Hi @Denny1,
Welcome to Google Cloud Community!
To connect your Google Cloud Run service to a Google Cloud SQL instance using PostgreSQL, here’s what you can do:
/cloudsql/INSTANCE_CONNECTION_NAME
, where the INSTANCE_CONNECTION_NAME
is formatted as project:region:instance-id
. You can find this information in the Google Cloud Console or by running gcloud sql instances describe [INSTANCE_NAME]
. The cool thing is that these connections are automatically encrypted, so no extra setup is needed. 5432
.For more detailed steps and examples, you may refer to this documentation guide on how to connect to Cloud SQL from Cloud Run, or you can check this quickstart for connecting from Cloud Run to Cloud SQL for PostgreSQL that does just that.
I hope the above information is helpful.
Hello. I have the same problem with a MySql cloud instance. I'm trying to connect to it via a fonction in cloud run. The cloud run service has access to the database instance in the service settings. Both proprietary and service accounts have SQL instance access rôle.
I'm using a cloud.sql.connector to initiate the connection, which works ok. But when connecting the resulting pool to the DB it says I dont have the rights to do that. Though I'm connected to the DB with Root account.
I'm testing the service in gcloud shell. The logged user is the proprietary account, not the service one (I dont know why it should make a difference). When testing the cloud SQL via the proxy it works fine.
Really, this is complex as hell to setup. I'm not even at a stage to access the DB from outside that it doesn't even work from inside. I dont understand what's going on.
If you need anymore info, I can provide. Thanks in advance.