MACHINE
LEARNING MODEL DEPLOYING IN AWS CLOUD
SERVER
Description:
- To create a web application we can use Flask as a backend framework.
- Flask is a micro backend framework that is perfectly suitable for creating a web application with Machine Learning Models.
- After creating a web application we need to deploy it on the cloud to make it available for all. For deploying easily on the cloud we can use AWS EC2 Instance.
- So here are the following steps from scratch to deploy a flask application with ML models on AWS EC2 Instance.
Prerequisites:
- Technology: Python, AWS, Putty
- Package Requirement: pip install flask
step
by step process to deploy a flask application with ml models on aws ec2
instance:
STEP1:
- Flask code in vs code .Run and check in local server
When the above command is executed then
the server is started locally at the URL Grey Li's Calculator. In this way, we can deploy the flask application locally on
the machine.
STEP2:
- Create AWS account and login
- our goal is to deploy flask application to AWS Cloud. For this, we need to have an AWS account.
- If you are new to AWS, You need to create an AWS account by providing your credit card details to avail of free tier services free for one year.
- After creating the account you need to go to AWS Management Console and need to sign in to AWS by using the account that you have just created
STEP3:
- create EC2 instance
- AWS Management Console and search for EC2 and need to click on running instances.
- Click on Launch Instance to create the new EC2 instance.
Go to EC2
dashboard launch instance and then create the instance
I. Choose an Amazon Machine Image (AMI):
- We need to choose AMI which means choosing an OS for the server.
- In this case, we can choose the UBUNTU 20.04which is a free tier and proceed next.
II. Choose Instance Type:
- Now we need to choose instance type for our server.
- In this case, we can go with a free tier instance.
- If yours is a company you can choose the paid ones.
III. Creating a Private Key Pair:
- Once you followed with the above steps you will be able to click on the launch button in “Review Instance Launch”. You will be getting a pop-up for choosing a private key pair.
- Let’s click on create a new private key pair and choose a keypair name.
- Now we need to click on the download key pair button to download it.
- Done with create instance launching
- we can be able to create an EC2 Instance. Now we need to go to view instances where you could be able to find the instance you have created.
Successfully
create instance ec2 and copy the url in public ipv4 DNS
STEP4:
Download
putty, putty gen
- Putty:- It is a free and open-source terminal emulator, serial console, and network file transfer application. It supports several network protocols, including SCP, SSH, Telnet, rlogin, and raw socket connection. It can also connect to a serial port
https://winscp.net/eng/download.php
- WinSCP:- It is a free and open-source SFTP, FTP, WebDAV, Amazon S3, and SCP client for Microsoft Windows. Its main function is secure file transfer between a local and a remote computer.
- convert a private key from PPM format which you have downloaded previously to PPK format using PuttyGen.
- Firstly open the putty
and load that to pem file paste and its will automatically connected into ppk file
- Here click load to update the pem file
- update pem file it will automatically converted to ppk file
STEP6:
- Open the winscp connect with aws sever we need to paste public ipv4 address link in host name click the advanced filter and select ssh then click authentication
- Final connect with winscp and click the yes to connect.
- Drag and drop the required file to deploy in aws ec2 instance.
- Now click on OK and go to log in. Now you can be able to connect with the ubuntu server.
- Now select the project files you wanted to add to the server and drag and drop to the right side section in the window.
- The file transfer starts and after a while files will be transferred.
STEP7:
- Open the putty to connect with ubutun server .
- Host name most be aws public ipv4 address link and paste over their.
- Now click on advanced options and go to “Authentication” and insert the created private key in PPK format.
- Some
command used in ubuntu to execute the aws server.
Install the Required Libraries and run the Flask Application:-
- Now once the terminal is ready now we need to run some commands before running the flask app.
- Firstly we need to update the OS and update pip to install libraries in the future.
- The command for performing above process is
sudo apt-get update && sudo
apt-get install python3-pip
Pip3 install -r requirements.txt
Now all the libraries are installed now we need to run the application by entering following command on ubuntu :
python3 app.py
Conclusion:-
- In this way, you can be able to deploy a flask web application with ML models using AWS EC2 instances.
No comments:
Post a Comment