Serving Streamlit on AWS

Hi all,

I was wondering what’s the best way to run Streamlit apps on cloud services like AWS or GCP? Is there a preferred hosting/containerization structure?

How does Streamlit scale to multiple users? Do we need to create a different instance of the app for each user?

Is it possible to use Streamlit as a front end to an api server?

Hey Karl!

Great questions — I’ll answer each one inline below:

the best way to go about serving a Streamlit app. Do you have a general philosophy in mind for doing this?

We tend to prefer creating a Dockerfile and then hosting the app as a container in your favorite provider (AWS, GCP, Heroku, Digital Ocean, etc). Let me know if you need some pointers there.

That said, we’re actually building a one-click solution for this right now :smiley:. We call it “Streamlit for Teams”. If you’re interested in participating in the beta, let us know! It’s early days, but we’re accepting alpha testers.

How does Streamlit scale? Do we need to create a different instance of the app for each user?

Each Streamlit server that you start with streamlit run foo.py can support multiple connected users. But since foo.py executes each time someone tweaks your app’s widgets, scalability depends a lot on your script foo.py itself. If you’re doing some heavy computation there, one user may slow down the other.

If you experience that problem, the solution is to have several replicated Streamlit servers and a load-balancer. This is the kind of stuff Streamlit for Teams will take care of automatically for you :wink:

Is it possible to use Streamlit as a front end to an api server?

Definitely! For example:

import streamlit as st
import request

# Build a UI
num = st.slider('Pick a number', 0, 100)

# Make request
resp = requests.post('https://myservice.com/multiply_by_2', data={'num': num})

# Do something with the response
result = resp.json()['result']
st.write('When you multiply that by 2 you get', result)

Can Streamlit interface with a Gunicorn/Nginx server to handle requests and responses?

Yes. Think of Streamlit like any other Python library — you can mix and match libraries to do whatever you want. In the example above I used the request library to make an RPC, for example.

Let me know if this helps.

3 Likes