Deployment of Streamlit app on AWS EC2 instance

Deployment of Streamlit app on AWS EC2 instance

Amazon Web Services(AWS)

AWS (Amazon Web Services) is a comprehensive, evolving cloud computing platform provided by Amazon that includes a mixture of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings. AWS services can offer an organization tools such as compute power, database storage and content delivery services.

AWS launched in 2006 from the internal infrastructure that Amazon.com built to handle its online retail operations. AWS was one of the first companies to introduce a pay-as-you-go cloud computing model that scales to provide users with compute, storage or throughput as needed.

AWS offers many different tools and solutions for enterprises and software developers that can be used in data centers in up to 190 countries. Groups such as government agencies, education institutions, nonprofits and private organizations can use AWS services.

Commonly Used Services Provided by AWS

The catalog of services available from Amazon Web Services is extensive -- storage, migration, security, customer engagement, developer tools and dozens more. These are among the most commonly used services from AWS:

  • Amazon EC2 - Providing secure compute capacity in the cloud, EC2 is resettable based on the user’s requirements. For instance, in a scenario in which web traffic varies, this service can expand its environment, behind the scenes, to three instances when required and then shrink to just one resource when load decreases. 
  • Amazon Elastic Beanstalk - Made with a number of programming languages, this service helps scale and deploy web applications. Simply upload the code and Elastic Beanstalk automatically handles the deployment from capacity provisioning to load balancing to auto-scaling to application health monitoring.
  • Amazon Lightsail - Simple to launch and manage, Amazon Lightsail is a virtual private server and includes everything needed to quickly launch a project on a virtual machine, like SSD-based storage, tools for data transfer, DNS management and a static IP.
  • Amazon Lambda - Lambda allows companies to run code with no need for provisioning and managing servers. It scales automatically from a few requests per day to thousands per second. Companies only pay for the compute times used; there is no charge when the code is not running.

For information about Streamlit refer my below Article:

Python Code to Create a Image Search Engine:

import streamlit as st
from PIL import Image
import requests


st.markdown("<h1 style='text-align: center; color: lightblue;'>The Maple Project</h1>", unsafe_allow_html=True)
st.text('')
st.markdown("<h2 style='text-align: center; color: lightblue;'>Welcome to Our Search Engine :-)</h2>", unsafe_allow_html=True)
st.text('')


image = Image.open('image3.jpg')
st.image(image)


download = st.text_input('Enter Anything to Search')


val=st.button("Submit")


if val:
    site = 'https://www.google.com/search?tbm=isch&q='+download
    getURL = requests.get(site, headers={"User-Agent":"Mozilla/5.0"})
    print(getURL.status_code)
    from bs4 import BeautifulSoup
    soup = BeautifulSoup(getURL.text, 'html.parser')
    images = soup.find_all('img')
    imageSources = []
    for image in images:
        imageSources.append(image.get('src'))
    imgList=[]
    for _ in imageSources:
        if 'https' in _:
            imgList.append(_)
    im=[]
    col1, col2, col3 = st.columns(3)
    col4, col5, col6 = st.columns(3) 
    with col1:
        im=Image.open(requests.get(imgList[0], stream=True).raw)
        st.image(im, width=200)
    with col2:
        im=Image.open(requests.get(imgList[1], stream=True).raw)
        st.image(im, width=200)
    with col3:
        im=Image.open(requests.get(imgList[2], stream=True).raw)
        st.image(im, width=200)
    with col4:
        im=Image.open(requests.get(imgList[3], stream=True).raw)
        st.image(im, width=200)
    with col5:
        im=Image.open(requests.get(imgList[4], stream=True).raw)
        st.image(im, width=200)
    with col6:
        im=Image.open(requests.get(imgList[5], stream=True).raw)
        st.image(im, width=200)

        

Steps to Launch an EC2 instance:

1. Login to your AWS Management Console

No alt text provided for this image

2. Search for EC2 services.

No alt text provided for this image

3. Launch an EC2 instance by selecting AMI, instance type, security group, VPC, and key-pair.

No alt text provided for this image

4. Connect to launched EC2 instance.

No alt text provided for this image

5. Upload your code to a S3 bucket.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

6. Get your code from S3 bucket to EC2 instance.

No alt text provided for this image

7. Install all the dependencies for the code in the EC2 instance.

No alt text provided for this image

8. Execute the Python Streamlit code.

No alt text provided for this image

9. Access the WebPage using the above External IP.

No alt text provided for this image
No alt text provided for this image

Thank you for Reading my article....

To view or add a comment, sign in

More articles by Tanu Vijay

  • Deployment of Streamlit App on Docker Container

    What is Streamlit? Streamlit is a free and open-source framework to rapidly build and share beautiful machine learning…

    2 Comments

Others also viewed

Explore content categories