Image 1- https://static7.depositphotos.com/1020804/754/i/600/depositphotos_7541455-stock-photo-green-beans.jpg
Whether you are an experienced or an aspiring data scientist, you must have worked on machine learning model development comprising of data cleaning, wrangling, comparing different ML models, training the models on Python Notebooks like Jupyter. All the above steps are of course undoable without the presence of such notebooks. However, these notebooks are limited for use by the developers as they cannot be directly utilized for an application by any non-technical user.
If you use any website for checking the weather forecasts of your city, the forecasts that you see are coming from a model that might have got developed in some notebook but the users are using the website for the forecasts.
As you must have guessed, there are therefore ways to convert the notebooks to a form that can be integrated into a product that can be accessed and utilized by any person – technical or non-technical users. This process is called ‘model deployment’.
AWS Elastic Beanstalk is a compute service that allows you to upload code of your web application along with environment configurations – based on which Elastic Beanstalk automatically provisions and deploys the necessary resources required within AWS to make the web app operational. These resources can include other AWS services and features like EC2 instances, elastic load balancing, autoscaling, etc.
As a data science professional, if you are not familiar with the nitty-gritty of model deployment, it would be ideal for you to use AWS Elastic Beanstalk to deploy your ML model as it automates and simplifies the whole process of deployment.
AWS Elastic Beanstalk as a service is free to use. However, the resources that are utilized to create the application like EC2 instances come at a charge as per the standard pricing policy at the time of deployment.
Things you need:
Flask is a web framework that can be used to build web apps with Python.
We can install ‘Flask’ using the following line of code :
pip install flask
Post installing, you could import the library and then create an application object. We add a route (“/”) to display the ‘Hello World! ’ message. A route enables mapping a web URL to a Python function. Whatever the function returns is shown to the user on the web URL.
from flask import Flask application = Flask(__name__) @app.route(“/”) def hello(): return “Hello World!” if __name__ == “__main__”: app.run()
Write the above lines of code in a .py file and name it as ‘application.py’.
We will need a requirements.txt file that lists all the libraries that we have used in our ‘application.py’ file. For our case, this consists of only the following line:
Flask==1.0.2
After we have created this file, we can zip these two files that can be later used while creating the application.
Sign in to AWS Console and search for AWS ElasticBeanstalk. Click on ‘Create Application. We can give our application a name. For the platform, we choose Python 3.8 and for the application code, we upload the .zip file that we created before.
Once we have uploaded the source code of our application, we can see the environment of our application getting created and finally the application getting created with a web URL assigned to the application.
EC2 is Amazon’s service that can be utilized for creating a server (or instances) in the AWS cloud. On the other hand, Elastic Beanstalk is one layer of abstraction away from the EC2 layer. Elastic Beanstalk sets up an “environment” for us that can contain multiple EC2 instances, an optional database, as well as a few other AWS components such as elastic load balancing, autoscaling, etc. Elastic Beanstalk manages these items for us whenever we want to update our application.
If you are trying to deploy a simple app in a short period of time(like an app that just displays a list of things), you can go for Elastic Beanstalk.
⚠️⚠️ However, there are some situations when you would like to prefer EC2 over AWS Elastic Beanstalk. If you have developed an app that has a lot of things going around in it like multiple file uploads, simultaneous calculations, continuous delivery of notifications to users, etc., it would be a better choice to leverage EC2.
About Author
Nibedita completed her master’s in Chemical Engineering from IIT Kharagpur in 2014 and is currently working as a Senior Consultant in an analytics firm. In her current capacity, she works on building AI/ML-based solutions for clients from an array of industries.
Image Sources:
1.https://static7.depositphotos.com/1020804/754/i/600/depositphotos_7541455-stock-photo-green-beans.jpg
2.https://data.solita.fi/wp-content/uploads/2020/05/anniina_kuva01artboard-2-1.png
3.https://blog.eventzilla.net/event-resources/10-icebreaker-ideas-for-networking-events/
4.https://www.kindpng.com/imgv/hRxxTh_qlik-dashboard-icon-hd-png-download/
The media shown in this article is not owned by Analytics Vidhya and are used at the Author’s discretion.