Deployment of a Machine Learning model into Amazon EC2 (Part 1- Warm-up of EC2)

  • In the previous article, we saw how to deploy a machine learning model into the local box.
  • Now, we will be deploying the model on Amazon EC2.
  • Before doing that, let’s first set up the environment for our trained machine learning model.
  • This can be done using Amazon EC2 through the following steps:

Sign in to AWS Management Console:

  • In order to deploy a model into Amazon EC2, at first, we will have to be familiar with the Amazon Web Services Dashboard.
  • So, sign up and make an AWS account by visiting https://aws.amazon.com/ and clicking on the signup button.
  • For a reference on how to sign up for amazon web services, you can refer to this video.
AWS Sign-in
  • Now after signing in into the AWS accounts and after the validation checks, you will land on the AWS Management Console.

Launch Instances:

Launch Instances for EC2
  • After successful registration, search for EC2 in the search bar and click on Launch Instances.
  • After you have successfully launched the instances, you’ll have to select the machine type.
  • Here, we will be using the free tier which gives us a Linux box with 2GB of RAM hence, we will select the Amazon Linux 2 AMI.
  • After that, you can continue the setup as per the default settings (using a t2.micro instance) and click Review and Launch.
Downloading the key-pair
  • Upon selecting the Launch button you’ll have to select a key pair.
  • You can create your own new key pair.
  • After the successful creation of the key pairs, you can simply download them into your local system. It will be saved as a pem file.
  • Now you’ll have to navigate back to the EC2 instances page the same way by searching EC2 on the search bar.
  • Then click on the instance that you have just launched.
  • After that, click on the Security tab at the bottom of the console and over there you can see a link in the form — sg-0aa552bfee276b14d.
  • On the next page scroll to the bottom and go to Edit Inbound Rules.
  • In the Inbound rules, add an All traffic rule with 0.0.0.0/0 CIDR block and then save.

Setup Putty for Deployment:

  • As for the next course of action, one is supposed to download and install PuTTy as per the default presets.
After successful installation, you should see PuTTYgen on your system
  • Next, one should open PuTTYgen from Windows.
PuTTY Key Generator
  • After that, the pem file needs to get loaded that was downloaded initially.
  • Keep in mind you keep all the files in the same directory otherwise it will challenging to connect to the right EC2 instance in AWS.
  • After the pem file is successfully loaded, one should save the file as a .ppk (for example filename.ppk) format in the same directory of the pem file.

Setup WinSCP:

  • After the setup of Putty, you need to download WinSCP from here.
  • One should keep in mind that at the time of the installation it should be a Typical Installation.
  • The user interface style should be selected as Commander.
  • Now as we open the WinSCP application we can see a hostname needs to be passed.
  • In order to find the hostname go to the EC2 instance, select it and click on connect.
  • After that click on SSH Client.
  • Here, you can find your hostname as ec2–54–198–143–216.compute-1.amazonaws.com.
  • You need to copy the hostname and paste it into the hostname section of WinSCP.
  • After that enter the username and click on Advanced.
  • After that click on authentication and select the three dots in the private key file section.
  • Over there, you’ll have to select the ppk file that was created and click open.
  • After that, click on Login and a popup window should open in front of you. Click on Yes.
  • In case you face any error please do have a look at the username.
  • You can read about the common error and how to resolve it here.
  • After the connection is established successfully, you’ll have to drag and drop the necessary files.
  • For this project, we have selected app.py, templates, the pickle file, and requirements.txt.

Installation of the required libraries into the server:

  • Now one issue is that, in the server, most of the libraries are not yet installed, and hence, we will have to manually install all the libraries.
  • In order to do so, open Putty.
  • Paste the hostname in the Host Name (or IP address) section.
  • Give a session name, here we have given MLDemoTest as the session name.
  • Next, click on SSH.
  • Next to the SSH button, you’ll find a (+) sign click that and then click on Auth.
  • Click Browse and feed the ppk file.
  • Now go to the session and click on save.
  • After that click on the session name and open it.
  • Now you can see that you’re able to access the terminal of that particular Linux server.
Linux terminal of our EC2 instance
  • You’ll have to pass on the username and you can see yourself logged in to the Linux server.
  • Now use the following command in order to install python 3 into the Linux box.
sudo yum install python3-pip

Conclusion:

  • So far in this article, we covered a high-level overview of how to set up our server into Amazon EC2.
  • We understood the setup of a Linux box.
  • In the next article, we will see how to deploy the trained machine learning model into Amazon EC2.

--

--

--

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The two projects created for each other, PipeFlare and 11Minutes, become partners

CBSE 12th Computer Science laboratory questions

Why is the Full Stack Developer role a bad idea?

3 Best Visual Studio Code Extensions

Integration of Kubernetes with Python — Flask

Free + Premium = Freemium Model, What is it??

Free Download Fern Wifi Cracker For Windows

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
INSAID

INSAID

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!

More from Medium

Introduction Cloud computing on Amazon Web Services

Document Classification using Amazon Comprehend

Introduction to Amazon S3

Creating Custom AMIs for use in AWS SageMaker Studio