I am facing some issues while trying to deploy my Streamlit app on AWS Elastic Beanstalk. The app works perfectly in my local environment but once deployed; I face challenges such as connection errors, environment variable misconfigurations & difficulty in setting up the requirements.txt file correctly for the environment.
I have tried tweaking configurations based on several guides but the app either crashes on start / shows a generic error page.
One specific issue seems to revolve around the correct version of Python & compatibility with the streamlit library. Even after specifying the Python version and updating my packages; I still face compatibility warnings. Additionally; I am unsure how to correctly set up the Elastic Beanstalk environment to handle Streamlitâs web server properly; especially with custom ports.
If anyone has successfully deployed a Streamlit app on AWS Elastic Beanstalk, I would love to know your approach, including how you handled environment variables, server port configurations & ensuring dependencies are resolved without errors.
I have checked HOWTO: Deploying Streamlit app to AWS Elastic Beanstalk (no containers)Java guide for reference .
Any examples, tutorials and step-by-step instructions would be immensely helpful!
To deploy your Streamlit app on AWS Elastic Beanstalk (EB), you need to consider how Elastic Beanstalk interacts with Python applications and how Streamlit, as a non-WSGI framework, fits into this environment.
Understanding Elastic Beanstalk and Streamlit
AWS Elastic Beanstalk is a platform that simplifies deploying and managing applications. For Python environments, EB typically expects a WSGI-compatible application (e.g., Flask or Django) , which it runs using a WSGI server such as Gunicorn.
However, Streamlit operates differently. Itâs not a WSGI application; instead, it runs its own web server, typically started with the command streamlit run app.py. This mismatch means that EBâs default behaviorâlooking for a WSGI entry pointâwonât work directly with Streamlit. Fortunately, EB allows you to override this default behavior using a Procfile, which lets you specify a custom command to run your application.
Deploying Streamlit on Elastic Beanstalk
Since Streamlit isnât WSGI-compatible, the simplest and most recommended approach is to use a Procfile to tell Elastic Beanstalk how to run your Streamlit app. Hereâs how you can do it:
Keep Your Streamlit App in app.py
The Streamlit code you provided should be saved as app.py. This file contains the core logic of your dashboard and is the main application you want to deploy.
Create a Procfile
Add a file named Procfile (no extension) in the root directory of your project with the following content:
web: streamlit run app.py --server.port=$PORT --server.headless=true
Explanation:
web: tells EB that this is the command for the web process.
streamlit run app.py is the standard command to start a Streamlit app.
--server.port=$PORT ensures Streamlit listens on the port assigned by EB, which is stored in the PORT environment variable (EB dynamically assigns this, often 5000, but should be 8501).
--server.headless=true is necessary because EB runs in a headless environment (no GUI), and Streamlit needs this flag to function properly.
Install Dependencies
Create a requirements.txt file listing your dependencies:
streamlit
numpy
matplotlib
EB will install these when deploying your application.
Directory Structure
Your project should look like this:
your-app/
âââ app.py # Your Streamlit app
âââ Procfile # Custom command for EB
âââ requirements.txt # Dependencies
Create a options.config
Create a .ebextensions folder inside your project with the file options.config:
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking âAccept allâ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.