GCP Cloud SQL Connection Refused scenarios in Python FastAPI Application
I've been banging my head against this for hours. I'm trying to connect my FastAPI application to a Cloud SQL PostgreSQL instance on GCP, but I'm working with a 'Connection Refused' behavior. I've set up a Cloud SQL instance and configured the necessary IAM permissions. However, whenever I try to connect using the `asyncpg` library, I receive the following behavior: `Connection refused: ('127.0.0.1', 5432)`. My database URL is set as follows: ```python DATABASE_URL = 'postgresql+asyncpg://username:password@127.0.0.1:5432/dbname' ``` I've tried replacing `127.0.0.1` with the actual Cloud SQL connection name, but that resulted in a different behavior: `OperationalError: connection to server failed`. I've also verified that the Cloud SQL instance allows connections from my application's IP address. My FastAPI app is running in a Docker container and I've ensured that the correct `cloudsql-proxy` is set up to tunnel the connection. The command I'm using to start the proxy is: ```bash ./cloud_sql_proxy -instances=my-project:us-central1:my-instance=tcp:5432 ``` When I test the connection using `psql` from my local machine, it works fine: ```bash psql -h 127.0.0.1 -U username -d dbname ``` Could anyone guide to figure out why my FastAPI application want to connect to the Cloud SQL instance and is throwing this 'Connection Refused' behavior? I'm using FastAPI version 0.68.0 and asyncpg version 0.24.0. Any insights would be greatly appreciated. This is part of a larger web app I'm building. Has anyone else encountered this?