Build Interactive Data Apps: Streamlit + Snowflake on AWS (Part 2) 🚀☁️
Welcome back to the second installment of our thrilling project journey! 🌐. In Part 1, we created a powerful Streamlit web app that analyzes online retail data from Snowflake. In this blog, we’ll guide you through the step-by-step process of deploying your powerful Streamlit web app to an AWS EC2 instance.By the end of this blog, your interactive web app will be up and running in the cloud.
Let’s dive into the exciting world of cloud deployment! 💻🌍
Topics covered.
- Launch an EC2 Instance on AWS ☁️.
- Connect to AWS EC2 Console in your Local Computer 💻.
- Creating a Python Environment 🐍.
- Uploading Files to the EC2 Environment 📤.
- Install Streamlit and Dependencies 📦.
- Edit Inbound Rules and Test the App 🧪
- Configures the application for deployment ⚙️ and launches it🛰️.
Ready to turn your local app into a global phenomenon? Buckle up and dive into the detailed steps below!
Resources Section:
- Comprehensive YouTube Video🎬: All step-by-step GIFs featured in the blog are compiled for a seamless viewing experience.
- GitHub Text File 📄: Detailed instructions and AWS deployment commands are neatly organized in a text file on our GitHub repository.
Step 1: - Launch an EC2 instance on AWS ☁️.
Launching an EC2 instance is a fundamental step in deploying your Streamlit application on AWS. This process involves creating a virtual server that will host your application.
The video tutorial shows how to launch an EC2 instance on AWS
Key Steps:
- Navigate to EC2 service.
- Click on Launch instance for creating a new instance: - Click the Launch Instances button to start the creation process.
- Name the instance.
- Create a new key pair for security: -
- Generate a new key pair, acting as your digital key to unlock access.
- Download and securely store the key pair file (.pem). ⚠️ Keep it confidential!
5. Allow necessary protocols like HTTP and HTTPS.
6. Launch the EC2 instance: - Review your choices and click Launch Instances.
Next, learn how to connect to the instance from your local computer.
Step 2: - Connect to AWS EC2 Console in your Local Computer 💻.
In this step, you’ll learn how to connect your AWS EC2 instance to your local computer. The connection process involves using Git Bash and SSH to establish a secure connection.
The video tutorial above, you’ll learn how to Connect your EC2 instance to your local computer.
Key Steps:
- Open Git Bash terminal
- Select your instance and start it: - Go to aws console and select instance.
- Connect to the instance: - With your EC2 instance selected, click the Connect button at the top of the EC2 Dashboard.
- Copy the provided SSH command: - Copy the provided SSH command from the dialog. The command will look something like this:
ssh -i "your-key-pair.pem" ec2-user@your-ec2-instance-ip
6. Paste the SSH command into Git Bash.
- Return to your Git Bash terminal.
- Paste the copied SSH command into Git Bash and press Enter.
7. Voilà! You’re now connected to the EC2 console.
Next, learn how to Create a Python Environment in EC2 console.
Step 3: - Creating a Python Environment 🐍.
In this step, you’ll create a Python environment on your AWS EC2 instance.
The video tutorial above, you’ll learn how to Create a Python Environment
Key steps:
- Open Git Bash terminal connected to your EC2 instance.
- Run the following command to create a Python virtual environment named myenv:
python3 -m venv myenv
3. Activate the Python environment
source myenv/bin/activate
4. Successfully created the Python environment.
Step 4: — Uploading Files to the EC2 Environment 📤.
In this step, you’ll be using the Secure Copy (SCP) command to transfer files from your local machine to your EC2 instance. The primary files you’ll be transferring are streamlit_app1.py
(your Streamlit application) and requirements.txt
(the file containing dependencies).
The video tutorial above shows how to smoothly transfer files to your EC2 environment.
Key Steps:
- Navigate to Command Prompt: - Open your command prompt or terminal on your local machine.
2. Upload Streamlit App to EC2 using SCP:
Execute the following SCP command to transfer your Streamlit application file (streamlit_app1.py
) to your EC2 instance
scp streamlit_app1.py <ec2-user>@<your-ec2-instance-ip>:/path/to/destination
3. Upload requirements.txt to EC2 using SCP:
Execute the following SCP command to transfer your requirements.txt(requirements.txt
) to your EC2 instance
scp requirements.txt <ec2-user>@<your-ec2-instance-ip>:/path/to/destination
4. Successfully Uploading Files to the EC2 Environment
▪️ SCP(Secure Copy command) Command Breakdown:
scp <your app name> <ec2-user>@<your-ec2-instance-ip>:/path/to/destination
- <your app name>: The file to upload
- <ec2-user@your-ec2-instance-ip>: Replace with your EC2 instance’s username and IP address .
- /path/to/destination: Replace with the destination path on the EC2 instance (obtained using pwd on EC2 CLI)
Next Up: Installing Streamlit and Dependencies
Step 5: - Install Streamlit and Dependencies 📦.
In this step, you’ll be installing Streamlit and the required dependencies for your application by executing the contents of the requirements.txt
file that you previously uploaded to your EC2 instance.
The video tutorial above shows How to Install python dependency in ec2.
Keys Steps:
- Launch Git Bash with EC2 Home Activated :- Ensure that your Git Bash terminal is connected to your EC2 instance. If you’re unsure, review the second step for establishing this connection.
- Installing all the dependency stored in requirements.txt: - Run the following command to install the dependencies:
pip install -r requirements.txt
3. Dependency installed successfully.
Next Up: Edit Inbound Rules and Test the App
Step 6: - Edit Inbound Rules and Test the App 🧪
In this step, you’ll configure the inbound rules on your EC2 instance to allow traffic on the specified port i.e. 8501 and test the functionality of your Streamlit application.
The video tutorial shows how to Edit Inbound Rules and Test the App
Keys Steps:
- Testing the webapp.
- Edit inbound rule to allow port 8501:-
- Go to your AWS Management Console.
- Navigate to the EC2 Dashboard.
- Select Your EC2 Instance
- Select Security Groups from the navigation pane.
- Find and select the security group associated with your EC2 instance.
- Click on the Inbound Rules tab.
- Add a new rule allowing inbound traffic on port 8501 (or the port your Streamlit app is configured to run on). Set the source to “0.0.0.0/0” for all incoming traffic.
- Save💾 the changes.
3. Congratulations on successfully running your web app!
Next Up: Configures the application for deployment ⚙️ and launches it🛰️.
Step 7: - Configures the application for deployment ⚙️ and launches it🛰️.
In this step, you’ll configure your Streamlit application for deployment and ensuring continuous operation.
The video tutorial shows how to ensure continuous app operation and successfully deploy the application.
Key Steps
- Keeping Your Website Alive with nohup:-Use the
nohup
command to keep your Streamlit application running even after you log out of your EC2 instance.
nohup streamlit run <streamlit_python_file.py> &
2. Testing your website.
3. Terminating the terminal: You can close the terminal using the ctrl+c
.
4. Testing your website: -After closing the terminal, verify that your Streamlit application is still accessible and running as expected.
Your web application is now deployed and ready for the world. Congratulations on a successful deployment 🎉!
Thanks for Reading📖💙
if you like my work the way to support me ….
- The best way is to support me is by following me on medium.
- Feel free to give claps so I know how helpful this post was to you.