1

I am a bit of a newbie with all this so please bear with me :)

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:

https://github.com/jaredap1995/Data-Pipeline-and-Web-App-Exercise-Prescriptions

JP1990
  • 35
  • 5

2 Answers2

1

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]
JP1990
  • 35
  • 5
0

The Cloud SQL Proxy is meant to be run as a separate process. Invoking it within Python is probably going to be painful.

Instead, consider using the Cloud SQL Python Connector -- it's entirely in-process and will remove the need to allowlist IP address ranges.

enocom
  • 1,496
  • 1
  • 15
  • 22
  • I tried (and likely messed something up) but stopped when I read in the documentation that the connector doesn’t create a network connection to my instance. The second line from the SQL connector documentation says “They can't provide a network path to a Cloud SQL instance if one is not already present.“ I read that as I need to have an open connection prior to using the connector, and since I didn’t have a connection I gave up using it – JP1990 Mar 23 '23 at 18:22
  • 1
    That sentence only means that if you're trying to access a private IP outside of a VPC, it's up to you to configure you network path (VPC peering, bastion box, etc). Otherwise, if you're working in the same VPC as your instance, or if you're just using public IP, you're good to go with the Connector. – enocom Mar 24 '23 at 03:47
  • Oh, well that makes much more sense lol. Thank you! – JP1990 Mar 24 '23 at 04:07