Deploy preprocessing logic into an ML model in a single endpoint using an inference pipeline in Amazon SageMaker
Created by Mohan Gowda Purushothama (AWS), Gabriel Rodriguez Garcia (AWS), and Mateusz Zaremba (AWS)
Summary
This pattern explains how to deploy multiple pipeline model objects in a single endpoint by using an inference pipeline in Amazon SageMaker. The pipeline model object represents different machine learning (ML) workflow stages, such as preprocessing, model inference, and postprocessing. To illustrate the deployment of serially connected pipeline model objects, this pattern shows you how to deploy a preprocessing Scikit-learn container and a regression model based on the linear learner algorithm built into SageMaker. The deployment is hosted behind a single endpoint in SageMaker.
Note
The deployment in this pattern uses the ml.m4.2xlarge instance type. We recommend using an instance type that aligns with your data size requirements and the complexity of your workflow. For more information, see Amazon SageMaker Pricing
Prerequisites and limitations
Prerequisites
An active AWS account
AWS Identity and Access Management (AWS IAM) role with basic SageMaker permissions and Amazon Simple Storage Service (Amazon S3) permissions
Product versions
Architecture
Target technology stack
Amazon Elastic Container Registry (Amazon ECR)
Amazon SageMaker
Amazon SageMaker Studio
Amazon Simple Storage Service (Amazon S3)
Real-time inference endpoint for Amazon SageMaker
Target architecture
The following diagram shows the architecture for the deployment of an Amazon SageMaker pipeline model object.

The diagram shows the following workflow:
A SageMaker notebook deploys a pipeline model.
An S3 bucket stores the model artifacts.
Amazon ECR gets the source container images from the S3 bucket.
Tools
AWS tools
Amazon Elastic Container Registry (Amazon ECR) is a managed container image registry service that’s secure, scalable, and reliable.
Amazon SageMaker is a managed ML service that helps you build and train ML models and then deploy them into a production-ready hosted environment.
Amazon SageMaker Studio is a web-based, integrated development environment (IDE) for ML that lets you build, train, debug, deploy, and monitor your ML models.
Amazon Simple Storage Service (Amazon S3) is a cloud-based object storage service that helps you store, protect, and retrieve any amount of data.
Code
The code for this pattern is available in the GitHub Inference Pipeline with Scikit-learn and Linear Learner
Epics
Task | Description | Skills required |
---|---|---|
Prepare the dataset for your regression task. | Open a notebook in Amazon SageMaker Studio. To import all necessary libraries and initialize your working environment, use the following example code in your notebook:
To download a sample dataset, add the following code to your notebook:
Note The example in this pattern uses the Abalone Data Set | Data scientist |
Upload the dataset to an S3 bucket. | In the notebook where you prepared your dataset earlier, add the following code to upload your sample data to an S3 bucket:
| Data scientist |
Task | Description | Skills required |
---|---|---|
Prepare the preprocessor.py script. |
| Data scientist |
Create the SKLearn preprocessor object. | To create an SKLearn preprocessor object (called SKLearn Estimator) that you can incorporate into your final inference pipeline, run the following code in your SageMaker notebook:
| Data scientist |
Test the preprocessor's inference. | To confirm that your preprocessor is defined correctly, launch a batch transform job by entering the following code in your SageMaker notebook:
|
Task | Description | Skills required |
---|---|---|
Create a model object. | To create a model object based on the linear learner algorithm, enter the following code in your SageMaker notebook:
The preceding code retrieves the relevant Amazon ECR Docker image from the public Amazon ECR Registry for the model, creates an estimator object, and then uses that object to train the regression model. | Data scientist |
Task | Description | Skills required |
---|---|---|
Deploy the pipeline model. | To create a pipeline model object (that is, a preprocessor object) and deploy the object, enter the following code in your SageMaker notebook:
NoteYou can adjust the instance type used in the model object to meet your needs. | Data scientist |
Test the inference. | To confirm the endpoint is working correctly, run the following sample inference code in your SageMaker notebook:
| Data scientist |