Deploy Machine Learning Model using Amazon SageMaker (Part 1)

Olusegun Ajose
7 min readMay 4, 2022

--

Creating and deploying high-quality machine learning models can be very challenging, even for experienced data scientists. Traditional machine learning development can be a complex, costly, and iterative process. The lack of integrated tools for the ML workflow makes this process even harder.

Amazon SageMaker aims to address this challenge by using integrated tools to automate labor-intensive manual processes and reduce human error and hardware costs.

This article is in different parts:

Set up Sage Maker — Part 1 (You are here)

Data Preprocessing — Part 2

Train the Model — Part 3

In this article, we will learn how to deploy ML models on AWS SageMaker.

You will understand AWS SageMaker, create your first notebook instance, download and explore a dataset, train and deploy your model and finally evaluate your model.

Before going ahead, kindly follow me here on Medium to ensure you get notified about new articles.

  1. What is Amazon Sagemaker?
  2. Who can use SageMaker?
  3. AWS SageMaker Workflow
  4. Create a Notebook Instance
  5. Download and Explore a Dataset
  6. Train a Model
  7. Deploy theModel
  8. Evaluate the Model

— -

  1. What is Amazon Sagemaker?

Amazon SageMaker is a fully managed machine learning service that enables data scientists and developers to quickly and easily build and train machine learning (ML) models, and then directly deploy them into a production-ready hosted environment.

It creates a fully managed ML instance in Amazon Elastic Compute Cloud (EC2) and provides an integrated Jupyter authoring notebook instance for easy access to your data sources for exploration and analysis, so you don’t have to manage servers. These notebooks include driver packages and libraries for common machine learning frameworks and deep learning platforms.

It comes loaded with some of the most popular and commonly used ML algorithms that are optimized to run efficiently against extremely large data in a distributed environment. In addition, SageMaker allows you to bring your algorithms and frameworks that have been packaged as a Docker container image.

2. Who can use SageMaker?

Business analysts use SageMaker Canvas visual interface to make ML predictions.

Data scientists use SageMaker Studio to prepare data and build, train, and deploy models.

SageMaker MLOps enables Machine Learning Engineers to deploy and manage models at scale.

3. AWS SageMaker Workflow

  1. A data scientist logs into the SageMaker console and launches a notebook instance.
  2. SageMaker provides a variety of built-in algorithms such as Linear Regression and Image Classification. The data scientist can also import their algorithm.
  3. The data scientist then specifies the location of the data in S3 and the preferred instance type.
  4. Next is to initiate the training process. Here, SageMaker uses automatic model tuning to find the hyperparameters that best optimize the algorithm.
  5. After building and training your models, it is time to deploy them. SageMaker automatically scales cloud infrastructure using a set of SageMaker instance types that includes several GPU accelerators and have been optimized for ML workloads.
  6. SageMaker then deploys across multiple availability zones, performs health checks, applies security patches, and sets up auto-scaling.
  7. SageMaker then establishes a secure HTTPS endpoint so that the data scientist can start performing inference.
  8. The data scientist can then track and trigger alarms for changes in production performance by Amazon Cloudwatch metrics.

IAM role

The IAM role is basically an AWS identity with permission policies that determine what the identity can and cannot do in AWS. Here, it is an AWS identity with permission to make AWS service requests.

IAM roles cannot make direct requests to your services, they are meant to be assumed by authorized entities such as IAM users, applications, or AWS services such as EC2 and notebook instances.

Notebook instances require permissions to call other services including SageMaker and S3.

Simple Storage Service (S3)

Amazon Simple Storage Service or Amazon S3 is a cloud service provided by AWS for secure, highly available, and redundant data storage. It is simply a public cloud storage resource that makes it simple and practical to collect, store, and analyze data — regardless of the format. It is very similar to file folders and contains both data and descriptive metadata.

4. Create a Notebook Instance

You need an AWS account to create a Notebook Instance. If you don’t have an account, you can get it here.

After logging into your AWS Management Console, search for Amazon SageMaker on the search bar, and click on the Amazon Sagemaker service in the results popup.

This will redirect you to the Amazon SageMaker Dashboard.

Here, you will see a lot of options on the left-hand side of the dashboard. These include Control Panel (Studio), Images, Search, Notebook (Notebook Instances), Processing, Training, and Inference. You even get to see links to SageMaker Tutorials and Documentation.

You can either create a project on Amazon SageMaker Studio or the Jupyter Notebook. We will be creating our first instance on the Jupyter Notebook.

Follow these steps to create your first notebook instance:

  1. Click on the drop-down menu of the notebook and then click on the notebook instances option. This will take you to the notebook instance dashboard where you can create a new instance or see a list of already created instances.

2. Click on the Create notebook instance button.

This will open a page to input details of the notebook instance.

3. Fill in the details.

You can give your notebook instance any name.

Notebook instance name: Demo

Notebook instance type: ml.t2.medium

For permissions and encryption, you need to create IAM roles.

We talked about IAM roles and S3 above. Remember that notebook instances require permissions to call other services including SageMaker and S3.

You need to create a new role that will provide access to specific S3 buckets.

4. Click on the create a new role above.

This pops up this Create an IAM role interface. You give the role access to any S3 bucket to specific S3 buckets.

Click the Create role button.

This creates the role and assigns it to the Notebook instance.

Once that is done, you are all set and you can go ahead and click the Create notebook instance button to create your first notebook instance.

5. Click the Create notebook instance

This usually takes some time, and the status will initially be Pending.

Once it is created, the status will change to InService.

There are two actions that you can perform when the Notebook’s status is InService. You can either Open Jupyter or Open JupyterLab.

5. Click on Open Jupyter to be redirected to your first empty notebook.

The notebook list is currently empty, so you need to create your first file.

6. Click on New dropdown in the top right corner and select conda_python3 option.

This will create your first file which you can name whatever you’d like to. Let’s just name it First Project.

As this is a Jupyter notebook, you can perform any task on it. Since you already know how to use the Jupyter notebook, this is going to be a piece of cake for you.

If you go back to the tab with the notebook list, you will see that it is no longer empty. The file you created is running.

You can also stop the notebook instance by going back to the Amazon SageMaker dashboard.

Select the Demo instance, click the Actions dropdown, and click stop.

The status will immediately change to Stopping. It will take some time before the instance is Stopped.

Now that you have an idea of how to create your first notebook instance, we are ready to move to the next part of the session.

We will continue in Part 2 of this article.

--

--

Olusegun Ajose

Data Scientist with experience in software development and machine learning. Currently focused on building responsible Artificial Intelligence solutions.