Using Google Cloud SQL Auth Proxy through Streamlit Cloud

Hello all, I am a bit of a newbie with all this so please bear with me :slight_smile:

I am trying to deploy an app on streamlit cloud so my fitness clients can access workouts, log and track progress etc. Everything works perfectly locally but when I try and deploy to streamlit cloud I get an error in the first few lines of my app() when it is supposed to connect to my database. The error is

OSError: [Errno 8] Exec format error: ‘./cloud-sql-proxy’

The code that produces the error is:

def app():
st.set_page_config(page_title=“Cabral Fitness Exercise Prescriptions”)
with st.spinner(‘Connecting to Cloud…Please Wait’):

    # Start the Cloud SQL proxy when the application starts
    proxy_process = subprocess.Popen(
    ['./cloud-sql-proxy', '--address', st.secrets.proxy_credentials.address, '--port', st.secrets.proxy_credentials.port, st.secrets.proxy_credentials.name])

    time.sleep(5) 

    conn = psycopg2.connect(**st.secrets.psycopg2_credentials)

I have been reading the Google Cloud SQL Auth proxy docs like crazy and feel like I am running in circles at this point. Any help would be greatly appreciated. The cloud-sql-proxy file does not seem to contain any important/secret information when I open it which is why I uploaded it to GitHub but perhaps I shouldn’t? I am sure it is running something special behind the scenes that allows it to work locally but not when i deploy to streamlit cloud. You can find the repo at:

I seemed to have solved it by adding all of streamlits outbound IP addresses (34.127.33.101 · 35.230.127.150 · 34.127.0.121 · 35.230.58.211 · 34.127.88.74 · 35.230.56.30.) as authorized networks in my SQL instance and then changing the psycopg2_credentials to connect to the public id address of my SQL instance rather than a manual IP address I had been setting.

I had previously been setting my own IP and port with SQL Auth proxy as such:

./cloud-sql-proxy --address 0.0.0.0 --port 1234 [INSTANCE_CONNECTION_NAME]
2 Likes

We can’t find the IP addresses easily any longer inside of Streamlit’s documentation.

Link explaining why