How To Deploy Streamlit Application on AWS EC2 Instance | Docker 🚀

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to my YouTube channel my name is Papi Hamed and I'll be your host so guys in this video I'm going to show you how we can deploy any kinds of stream lead application on the AWS Cloud so guys I have seen people are facing these kinds of issue like whenever they are trying to deploy this kind of streamlit application on the AWS Cloud uh they are having some added okay they're facing some of the difficulties so that's why I thought let's create one video on top of it like how we can deploy uh this kinds of streamlit any kinds of streamlit application you are creating uh that app like how we can deploy in the AWS Cloud so guys here we'll be using one specific service called ec2 instance so so guys if you don't know ec2 is a virtual machine service from the AWS itself so here actually you can launch any kinds of uh like operating system uh we call it instance okay and there actually you can do the deployment now uh in this video I'm going to show you or two technique uh to do the deployment uh these kinds of streamlit application uh so the first technique I am going to to show you the simple technique so basically we'll be like replying one simple streamlined application with the help of GitHub and ec2 instance so first of all we'll be committing our code in our GitHub and from the GitHub itself and guys from the GitHub itself we will be cloning the repository in our ec2 machine and from there only we'll be doing the deployment all right and the second technique I'm going to show you let's say if you want to create any kinds of images okay let's say Docker images and all at the time how to do it okay so here actually I have integrated another technique here so we'll be again creating one streamlip application simple application so here actually I'm going to use one simple just welcome screen application but let's say you can take any kinds of project okay it can be ml project it can be DL project okay any kinds of project you can take using uh stream lead okay package and you can do the deployment using the same video all right now again I will be committing the code in my GitHub I'm from the GitHub itself I will be again like pulling the code in my Amazon ec2 instance and from there only I will be creating one Docker image and that Docker image actually I'll be pushing to the docker Hub so here instead of Docker Hub you can also use uh elastic container registry that means ECR service from the Amazon itself so this is kinds of Docker Hub only but here I'm going to use some of the free services I'm just telling you like how to use some of the free services as well because if you are using Docker Hub you don't need to pay for it okay that's why I have integrated Docker up with that but you can also integrate Amazon ECR with that okay it's it's very easy so guys here I'm going to show you after creating the docker image how we can push this kinds of Docker image to the docker Hub and how we can store these these kinds of emails okay to the hub so that whenever you need it okay later on you can pull from The Hub itself all right so these two technique actually I'm going to show you so first of all let's start with our first technique simple technique first of all uh you should have one streamlit app so guys here I have already created one GitHub repository I will give the link in the description so that you can get from here and I have already mentioned all the commands actually you need to run okay to the deployment so guys you see this is the Simple app and if you just open this app.pi so this is just a welcome screen app using stream lead as you can see see if you're using htmlit like uh you need to write very less line of code here see using just a two line of code you can launch one welcome screen here okay but let's see if you are not using stream lead if you're using HTML CSS you need to write again HTML CSS score for it okay but uh this is the convenience of using a streamlit if you don't know HTML CSS code just use it okay and it has some of the method already pre-built just try to call that and try to put your text it will automatically launch the server for you all right so this is the simple application I have created now you just replace with any kinds of project here okay no issue with that all right and uh this is the requirement of txt I have created so the dependency you have something called stream date here all right so this is a simple app and these are the command I I have already added okay in this repository so let's say we have already committed our code in my GitHub and it is presented okay see this is presented in my GitHub now what I will do I will logging with my AWS console so I have already logged in with my AWS console as you can see you just also log in with your account so here I'm going to use something called ec2 service okay just search for ec2 virtual service in Cloud just go with ec2 now here I'll be launching one instance I'll click on launch instance and give the name of the instance I will give just a simple extremely tab okay hdf and uh select the Ubuntu machine from here and machine emails just take 22.0 for LTS it's completely fine and here instead of using T2 micro just take at least 2 GB Ram here 2GB memory T2 small okay this one now you can create one key here this is required actually uh but see this thing we won't be using so this keeper actually you need to get the Pam file okay so let's say if you want to access your instance using some third party tool let's say mobile stream or let's say putty at the time this spam file is required in this pen file it will have the security code okay to authenticate with your account uh but uh if you are ignoring so it will Pro error so it is required as you can see so uh to ignore this error just create click on the create a key pair and give the name so I'll give stf okay and just create the key pair so it will download button Pam file for you okay see this is the payment file it has downloaded now make sure you have selected the same thing uh for me it's SDR foreign these two I think you need to allow now uh take 8GB memory it's completely fine because we have very simple app here all right now I'll just launch the instance here now click on view instance all right now status should be running let's wait so guys as you can see my status is running now I'll click on instance ID so here the first thing you need to do the port mapping okay so if you don't know streamlit runs on the port of this port okay so 8501 so this is the default Port actually streamlined app will run so you can't change this port because by default in the streamlit they have configured this port for you all right so I need to add this port number in my instance I have created now what is the port number it's 8501 now to add this port in your instance just go to the security okay here you can see the security now here you have one option called Security Group I'll click on Security Group and uh right hand side I think it is visible or not on the right hand side you can see something called edit and bound rules okay I'll click here then from here I'll click on ADD rules now here you just need to select the custom TCP one it's fine now just add the port here so it was eight five zero one this is the port now here just select the zero zero zero this one and just click on uh save Okay click on Save now our Port has been added as you can see uh 8501 so we have successfully added this port here I've already mentioned all right now what I need to do I need to go back to my instance I will click on the instance go to the instance ID again and from here just connect your instance here okay I'll just click on connect now let me Zoom a little bit okay let me clear it all right so the first thing uh we need to execute some of the command to upgrade our instance so let's do the sudo apt update first of all make sure you are using this repository how to reply streamly tab or AC to instance okay uh I will give the link in the description so first of all I will copy this command just copy the command one by one and execute it here okay let's execute it's done now I'll copy the second command again let's execute it okay it's done then I will copy the third command so guys if you are getting this kinds of window just press enter from the keyboard again I will press enter so it will disappear and it will install everything all right it's done now I will copy this command so it will basically install some of the necessary tools here that's a gate then unzip these are the tools actually it will install because I need to clone this repository here okay so for this I need the GitHub git installed okay that is why now let me again press enter okay it's done then I will copy uh uh okay so I have added two time this command okay I will Rectify it no issue you just need to execute one time now you need to clone the repository okay so this repository you need to clone so first of all click on the code and copy this HTTP link address and uh and open up your instance and here first of all Let Me Clear it and I'll just write gate column I'll paste the link here and let's clone it okay now if I do LS here I should see the repository yes now let me go to this one CD deployment streamed it now let me clear it now if I again do LS see all the files I had in my repository it is now present here so the first thing what I need to do after closing the repository I need to upgrade my peep okay so this is the command to upgrade your peep so let me execute it here now it is asking for do you want to upgrade uh yes I'll tell yes just give y uh see it it's again uh so guys this window again came so press enter again I will press enter so yeah it's done now let me clear it okay now I need to uh install my requirements okay so here if you see I have requirement.txt file if I do a LS this is the txt file I need to install it so let me install so guys my requirement uh installation is done now I can start my server so to start the server this is the command a Python 3 hyper name stream late run app.pi okay because if you see here I have my app.pi here this is the end point right and this command actually uh will running your app temporarily okay so let me show you like what I'm saying so first of all let me copy the command and if I execute this command here all right see my application will start see my application is running now to get the application go back to your instance let me go back to my instance here I will go to my instance ID again and just copy this public IP address okay copy this public IP address and take a new tab paste it here and give the port number okay give this clone port number it was uh uh I think uh what is the port number eight eight five zero one so eight five zero one if I give and press enter see it will launch my streamlit app and it will show you the welcome screen see guys okay that means my application is running fine now if I do the refresh again see it's running fine okay now let's say if you close this terminal okay let's say if I close this terminal uh let me close it I will press Ctrl C see I have uh stopped my execution here and you can also close this terminal you can also close it so after closing you will observe if you again refresh the page see it won't be running because you have already stopped the execution there but uh what is the use of the deployment then okay I I want my application should be running all time if I am also closing my AWS tab also okay it should be running always so how to do it so to run it there is a permanent command actually you need to run so this is the command Noha Python 3 uh hyponym streamlined run app.pi so this is the command with that you just need to add this no-hub command okay now let me copy this command all right now let me execute it here and I will see the magic so if I run this command if I come here and let's say I will close this tab okay let's say I will close this tab after closing the tab if I again refresh this page see it's running okay it's running perfectly that that means uh if you want your app should be running permanently so you can execute this command and if you are just doing the experiment you can run this command temporarily Run Okay so yes guys this is the simple deployment uh like how to do the deployment on the ec2 machine okay this kind of uh streamlit app now I will show you this one okay I will show you this Docker one like how to create a Docker image and uh how to like run it in the ec2 machine and how to also push the image to our Docker Hub so before that I I just want to show you how to terminate this instance as well because see if you if you see this application is running okay every time it's running now I also need to terminate it okay if you're a lot if you're not terminating it if you leave it like that so it will charge you okay so it's better practice whenever you have done the deployment if you are not using it just try to terminate it all right so to terminate it I will go back to my instance and just select the app you created yet select the instance you created now click on the instance State okay and just click on the terminate and I will click on terminate so you will see it will shut down then after that after sometimes it will delete everything all the instance form here okay now if I execute it again my instance has been deleted that's why it's not running now let me close it all right now let me show you this approach technique too first of all I will be committing my code in my GitHub from the GitHub itself again I'll be quoting my code in the Amazon ec2 then I'll be building the docker name is then after building the docker image I'll push this Docker image to the docker Hub all right not to do it again I need to create one ec2 machine here so just because that this machine I have already closed okay let me create a new one I will click on the long stance and here I will give SD docker test you can give any name no issue then again I will select Ubuntu machine same version you can use and again just go with T2 small all right now select the key here key value here I will select the previous one I created uh St test I think it was stf yes now uh I'll activate these two things now 8GB is fine for me then I will launch the instance here now click on view instance uh this is pending let's wait it should be running and previous one has been terminated okay after sometimes it will delete from here so see guys my instance is running now let me click on the instance ID so now this is the repository we'll be using uh so this depository name is streamlit app Docker image I will give the link in the description now here again we'll be following some of the commands Okay and this is the app guys so what is the changes I have done here I have added this Docker file on me here if you see the docker file let me open see this is the docker command so first of all I'm taking my python 3.8 slim Buster image then I'm exposing the port to this 8501 because I'm already because I already told you this streamlit will run on this port then I'm installing some of the required tools here okay let's say I'm first of all uh updating my apt gate and all then these are the tools actually I'm installing here then I'm creating my working directories and inside working directories I'm copying all of my source code then I'm installing my requirement.txt after that this is the entry command okay so if you run this so it will uh start your server okay you can see this is the command and this is the port actually I'm giving here so this is the docker file you need to create and this is the docker ignore you need to create so whatever files you want to ignore here you can mention it let's say if you have created an environment here you can ignore it because this environment I don't need okay for this image that is why now this is the same app if I open it this is the same app welcome screen and this is the requirement.txt simple app okay the same app only the emails I have added here now what I need to do again I need to do the port mapping here okay here I have already mentioned do the port mapping to the 8501 so again let's go to the security and here I have the security group let me click here now right hand side you can see edit and bound rules click here and uh let's add the rules custom TCP is fine output should be eight zero sorry eight five zero one again just verify it eight five zero one yes now select this zero zero zero block and uh save the rules so once it is done let me go back to my instance uh I'll click on the instance ID now again I will connect me to the connect let me clear the terminal okay now again let's run this command one by one so first of all I will copy this command and bring the sudo upgrade here it's done now let's copy the second one so do I PT get update just give y to continue now uh it's giving this window press enter okay it's done now let me clear okay now what do you need to do uh because I already told you I'll be using Docker here so to use the docker in The Institute instance you first of all need to install the docker so to install the docker these are the command actually you need to execute okay so let's copy one by one I will again copy this command so guys it's done now let's copy the third command all right now I'll copy the last command so I hope my Docker should be installed now now to check the docker just write this command Docker hyphen hyphen version okay if you run this command it should show the version of the docker C this is the docker version that means my Docker has been installed and it's running now uh what you need to do you need to clone this repository so again I will copy this uh link of the Repository make sure selected https now just write git clone paste it so it has already grown now to check it just write LS command system Docker image it's there now let's go inside I'll just write CD stream lead all right now if I do LS see all the piles files should be present here all right now let me clear it now what I will do first of all I need to uh build the docker image okay to build a Docker image this is the command you need to execute so uh I will just copy this command Docker base hypnt then you need to specify the username so see here I'm going to push my Docker image to my Docker here Hub so first of all you just need to log in with your Docker app so let me search for Docker hub so this is the docker hub uh make sure you have created account here and logging with your account here so I already have the account and it is online log link and here I had some image okay present previously so this image actually I already created with the names with the same name uh St app I've already created so I'll change the name only all right so first of all what I will do I will change the name then I will build a Docker image so let me copy this command first of all copy this command I'll take a new tab and here I will change the name of the app only here so St app let's give one here okay let's give one year because it was AST app here all right now I'll give just one stm1 latest otherwise let's uh change the name here I'll give SD test stts tab okay this is the name I have given now let me copy the command and here I will execute it this is the command Docker builds happen t uh this is the username of your Docker Hub ENT puppy as you can see ENT puppy make sure you are giving your username not my username all right and slash your app name like Docker image name you want to create and the tag this is the latest uh like image I want to create and Dot means uh it will take the docker file from the here itself all right now let me execute the command see it will first of all build a Docker image of your entire source code so it may take some time that's right I will come back when it is done so guys you can see my image building is done now if you want to check whether this image has been built or not there is a command just find docker uh images okay so this is the command now you can see uh this image has been built okay this is the same name I have given latest and this the image ID and two minutes ago it has created and the size of the image is 925 MB on it now what I will do my image has been built uh now I need to uh personal test whether this image is correctly running or not here okay so this is the command so let me copy the command I'll copy the command and I will just change the name of my app here instead of SD app I'll give SD test app and guys uh the same command you can run from your uh like Docker desktop as well let's say instead of launching uh Docker into the ec2 instance you can also install Docker in your local and you can also build the image and from here only you can push the image to the docker app okay that's how you can also do but I'm expecting most of you only having Docker installed in your system that's why I'm everything doing in the uh like you can say Cloud Server all right but you can also run it from your local machine also it's completely fine now this is the command you just need to run now let's run it yeah so if you execute the command so it will basically run this image and here I'm doing the port mapping uh it will run on this port and I'm running on detach mode okay Detachment if you are also closing this tab it will keep on running all right now this is the app name I'm giving here ENT Buffy St app test okay this is the app name now let me execute see this uh image is running now to test it I will go back to my instance again uh click on the instance ID copy this public IP address and paste it in a new tab and give the port number as 8 5 0 1. now see this app is running fine all right okay this app is running uh and uh see we have first of all containerized our entire source code okay using Docker and this Docker image we are running this is like more powerful deployment guys okay than your previous one because here you have containerized your code using the help of Docker now it is running on the docker container all right now this thing is fine now what are you what I will do uh see guys I have one image here it is present here but let's say you also want to store this image to some stories okay let's say if you want to use this image later on so you can use Docker Hub you can push this image to the docker Hub here and whenever you need it you just call from here so let's do it so before that uh what I will do first of all I will uh I'll stop the container okay stop the container because I want to run my emails from my Docker Hub only okay so for this this is the command I have already given here uh first of all if you want to see whether any image is running or not any content is running or not just write dockerps dockerps so if you run this see one container is running now I need to stop the container to stop the container just uh run this command I can't stop uh here just write docker stop should be stopped and give the container ID just copy and paste it here now it has been stopped now if I again run the same command Docker PS see there there is no container running but I also need to delete this container because it's not running but this container is present okay it will occupy my memory so if you want to delete it just execute this command copy and paste it here so it will remove so it will remove all the containers see it has uh deleted my container now what I will do first of all I need to log in with my Docker Hub so this is the command let's copy and paste it here Docker login so it will ask for the username make sure you are giving the same username whenever you try to log in with your Docker app okay so I'll give my username it was ENT puppy and it will ask for the password the same password you need to use in your Docker app only okay so let me give my password see it will say uh tell you login success if it is done now I need to push my image so to push the image this is the code Docker push now let's copy and just let me now see a connection error because I have already deleted my container okay now let me close it others let's keep it here I will just change the name it should be SD test app now if I do it so I think remember I had one image here docker images see this is the image I need to push to my Docker now this is the command I'm giving the same name as you can see now let's execute now see it's pushing this image to my Docker Hub now let's wait once it is done you will see the image there uh so guys you can see my image has been pushed now let's go back to my Docker Hub and let's refresh now see this stf test is present okay that means we have successfully pushed our image in the docker app now if you click here this is the public view just click on the public View and if you want to pull this image this is the command Okay Docker pull stf but before pulling it first of all I will delete my local image I have in my instance first of all let me delete it clear sorry it should be clear now if I show you docker images type in it see already I have one image the same image first of all I will delete it to delete this image uh you need to run this command you need to run this command so here uh Docker rdmi let's run it docker sorry it should be Docker RMI now just copy the name of the Repository copy and paste it here so it's done now if I again execute my Docker image a now see there is no repository now I can pull this repository just copy this command Docker pull and uh sorry it should be pasted yeah now if I pull it see now it has pulled now if I again run this command Docker image is a now see this image is present again here okay now what I will do uh I will execute the same image all right again so this is the command I executed let me copy only I just need to change the name so it should be SD app test test app copy and execute it okay it's running now let's go back to my app and let's refresh this page again now guys see it's running okay that means we have successfully deployed and we have also successfully pushed this image to our Docker Hub it is working fine now uh you if you're not using it you can also terminate it I already showed you how to terminate just go to the instance and select the instance you want to terminate and click on the instance State and terminate instance all right yeah so uh yes guys this is all about uh about the deployment case okay how to deploy this kind of stimuli tab on the AWS Cloud I hope you like this particular video if you have liked this particular video try to subscribe to my Channel Try to share this video with your friends and family and this is the request guys to everyone try to support my channel so that I can bring these kinds of content more in future okay so yes guys this is all about from my side thank you so much for watching this video and I will see you next time
Info
Channel: DSwithBappy
Views: 8,676
Rating: undefined out of 5
Keywords: Streamlit deployment guide on EC2, AWS EC2 Streamlit deployment walkthrough, Deploying Python app with Streamlit on AWS, Streamlit AWS EC2 configuration, AWS EC2 instance for Streamlit app, Streamlit deployment best practices, AWS EC2 deployment tips for Streamlit, Setting up Streamlit on AWS step-by-step, Streamlit app hosting on AWS, AWS EC2 deployment for beginners, Streamlit deployment challenges on AWS, Secure Streamlit deployment on AWS EC2
Id: DflWqmppOAg
Channel Id: undefined
Length: 31min 3sec (1863 seconds)
Published: Wed Aug 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.