Deployment of a Machine Learning model into Amazon EC2(Part 2- Real-Time Deployment)

Accredian Publication
3 min readJan 23, 2022

--

by Pronay Ghosh and Hiren Rupchandani

  • In the previous article, we set up a Linux-based EC2 instance so that we can deploy our model on AWS EC2.
  • Let’s proceed with model deployment!

Creating a Security Group:

  • Now that we have our EC2 instance, we will have to set up the EC2 instance accessible from anywhere.
Security Group
  • To do so, go to the EC2 instance and select the security group.
  • Select Inbound and click on add rule.
  • Set the type of the rule to All traffic.
Setting Inbound rules
  • In the source information, set the permission as Anywhere.
  • This indicates that we can use access the EC2 instance from anywhere with IPv4 and IPv6 network protocols.

Setting up the Network Interfaces:

  • After setting up the security groups, we need to go to the Network Interfaces section.
Network Interfaces
  • Right-click on the interface and select Change security groups.
Change Security groups

Setting up the system dependencies:

  • Now, we need to go back to the terminal and install the system dependencies in order to deploy our model.
  • For that, we will use the following command:
pip3 install -r requirements.txt
Installing using requirements.txt
  • After running the command we can see that the system dependencies have been successfully installed.
  • Upon successful installation, run the following command in the terminal:
python3 app.py
Running the app
  • We can now see that our app is running on port number 5000

Deploying into EC2:

  • As the final step, we will have to go back to the EC2 instances in the AWS management console.
Connecting the EC2 instance
  • From the instances, select the EC2 instance.
  • After that, we will have to click on actions and click on connect. We should be able to see an URL.
Getting the URL
  • We will simply add the port number. Here, the port number is 5000. So we can add the port number as follows:
<The EC2 URL>/5000
  • Open this entire link in a new tab and you can see your model live on Amazon Elastic Compute Cloud (EC2).

Conclusion:

  • In this article, we covered a high-level overview of how to deploy a machine learning model into Amazon EC2.
  • In the next article, we will see how the high-level overview of Amazon S3.
  • We will also understand how to run a jupyter notebook into the cloud using Amazon Sagemaker.

Follow us for more upcoming future articles related to Data Science, Machine Learning, and Artificial Intelligence.

Also, Do give us a Clapđź‘Ź if you find this article useful as your encouragement catalyzes inspiration for and helps to create more cool stuff like this.

--

--

Accredian Publication

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!