Cloud SQL with Cloud Run

I am trying deploy phoenix app to cloud run every thing works locally fine using public IP but when i deployed to cloud run the app could not connect to database

  • Public IP
  • Private IP
  • Socket

with socket the error was

00:26:07.027 [error] Postgrex.Protocol (#PID<0.3424.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (<project_id>:<region>:<instance-name>/.s.PGSQL.5432): connection refused - :econnrefused
Cloud SQL connection failed. Please see https://cloud.google.com/sql/docs/mysql/connect-run for additional details: ensure that the account has access to "<project_id>:<region>:<instance-name>" (and make sure there's no typo in that name). Error during generateEphemeral for <project_id>:<region>:<instance-name>: googleapi: Error 403: boss::NOT_AUTHORIZED: Not authorized to access resource. Possibly missing permission cloudsql.instances.connect on resource instances/<instance-name>., forbidden

I had issues getting started with Cloud Run and Cloud SQL also. I wrote up the answers here: Deploy a Phoenix application to Google Cloud Run and Cloud SQL · stibbard.io

1 Like

Nice notes! Thanks for sharing.