Serving Estimator Models with Serverless Endpoints

Introduction & Overview

Welcome to another lesson on deploying models with SageMaker! In the previous unit, you learned how to deploy a locally trained model to a SageMaker serverless endpoint. You gained valuable experience with the fundamental concepts of model deployment: packaging model artifacts, uploading to S3, creating entry point scripts, and configuring serverless inference. Now it's time to build on that foundation and explore a more streamlined deployment workflow.

In this lesson, you'll learn how to deploy models that were trained directly within the SageMaker ecosystem using SageMaker estimators. This represents a natural progression in your learning journey because, when you train models using SageMaker's built-in training capabilities, the deployment process becomes significantly more streamlined. Instead of manually packaging and uploading model artifacts, SageMaker automatically handles these steps for you since the model artifacts are already stored within the SageMaker environment.

The key difference you'll discover is that SageMaker estimators come with built-in deployment capabilities that eliminate much of the manual configuration work you performed in the previous lesson. You'll learn how to attach to existing training jobs, leverage SageMaker's automatic artifact management, and deploy models with just a few lines of code while still maintaining the cost-effective benefits of serverless inference.

By the end of this lesson, you'll understand how to retrieve completed training jobs from your SageMaker environment, attach to those training jobs to create deployable estimators, configure serverless inference settings for optimal performance and cost management, and deploy estimator models to live endpoints that can serve real-time predictions. This knowledge will prepare you for more advanced deployment scenarios and help you build efficient machine learning workflows entirely within the SageMaker ecosystem.

Retrieving and Attaching to a Completed Training Job

When you train models using SageMaker estimators, the training process creates a training job that stores all the necessary information about your model, including the trained artifacts, training configuration, and metadata. To deploy one of these models, you first need to retrieve information about the completed training job and then attach to it to create a deployable estimator object.

As you did in the previous course when downloading model artifacts, you'll start by initializing a SageMaker session and retrieving your completed training jobs:

import sagemaker
from sagemaker.sklearn.estimator import SKLearn

# Initialize SageMaker session
sagemaker_session = sagemaker.Session()

# List most recent completed training job
training_jobs = sagemaker_session.sagemaker_client.list_training_jobs(
    SortBy='CreationTime',                 # Sort jobs by creation time
    SortOrder='Descending',                # Newest jobs first
    StatusEquals='Completed',              # Only include completed jobs
    NameContains='sagemaker-scikit-learn'  # Filter to sklearn estimator jobs
)

# Extract the name of the latest training job
TRAINING_JOB_NAME = training_jobs['TrainingJobSummaries'][0]['TrainingJobName']

We're filtering for jobs containing sagemaker-scikit-learn because this is the default naming pattern that SageMaker uses for sklearn estimator training jobs. This helps us quickly identify the relevant training jobs from your account.

Now comes the key difference from the previous lesson. Instead of manually downloading and packaging model artifacts, you can attach directly to the existing training job to recreate the estimator:

Python
# Attach to existing training job
estimator = SKLearn.attach(TRAINING_JOB_NAME)

The SKLearn.attach() method reconstructs an estimator object from the completed training job, automatically populating all the information SageMaker needs for deployment — the model artifacts location, training configuration, and framework specifications. This eliminates the manual packaging and uploading steps you performed in the previous lesson, since the estimator already has access to everything stored within the SageMaker environment.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal