Skip to main content
This lesson demonstrates how to use the SageMaker Model Registry to track model artifacts, manage versions, and deploy approved models. The examples are executed from a Jupyter notebook in SageMaker Studio and use the SageMaker Python SDK along with Boto3. We will:
  • register a model artifact as a model package,
  • register that model into the SageMaker Model Registry with an approval status, and
  • approve a model version and obtain the latest approved model for deployment.
A slide titled "Agenda" listing three steps for using SageMaker Model Registry: (1) register a model artifact as a model package, (2) register a model with pending approval status into the registry, and (3) approve and deploy a model from the registry.
This notebook covers the following SageMaker SDK usage:
  1. create a legacy model package using Model.create,
  2. register a model into the Model Registry using Model.register,
  3. list and obtain the latest approved package from the registry, and
  4. deploy the approved package to an endpoint.
A slide titled "Demo Steps" that outlines a four-step workflow for registering and deploying a machine learning model. The steps are: 01 Open Notebook, 02 Register Basic Model Package, 03 Register Model into Model Registry, and 04 Approve & Deploy.
Getting started: open SageMaker Studio, launch JupyterLab, and open the notebook named “Model Registry Demo”.
A screenshot of an AWS SageMaker / JupyterLab interface showing a file browser on the left and a Launcher on the right. The Launcher displays notebook, console, and other app icons (Python, Glue/Spark, Terminal, Markdown, etc.).

1. Imports and session setup

Start by importing required libraries and creating a SageMaker session and role reference. This session object is used throughout the notebook for SDK operations.
# imports and session setup
import boto3
import sagemaker
from sagemaker import get_execution_role
from sagemaker.session import Session
from sagemaker import Model, ModelPackage

sagemaker_session = Session()
role = get_execution_role()

print(role)
The printed value is the IAM execution role ARN associated with your notebook environment.

2. Legacy model package (Model.create)

If you already have a trained model artifact saved in S3 and want a quick way to create a SageMaker model package (legacy flow), call Model.create() by supplying the S3 model artifact and the appropriate container image for the framework.
  • model artifact (output of a training job)
  • container image URI for the training framework (for example, Linear Learner)
Example:
# Reference model artifact in S3 (this is the trained model output)
model_artifact = 's3://sagemaker-eu-central-1-485186561655/house-price-linearlearner-demo/output/linear-learner-2025-05-06-13-48-11-566/output/model.tar.gz'

# Determine region and fetch container image URI for the Linear Learner framework
region = sagemaker_session.boto_region_name
container_image_uri = sagemaker.image_uris.retrieve(framework="linear-learner", region=region)

print(f"SageMaker Linear Learner Image URI: {container_image_uri}")

# Assign a meaningful name to the model
model_name = 'kodekloud-house-prices-demo'

# Create the SageMaker model (legacy model package)
model = Model(
    image_uri=container_image_uri,
    model_data=model_artifact,
    role=role,
    name=model_name
)

# Register the model package (legacy)
model.create()
After calling model.create(), the model package shows up in the SageMaker console under Inference → Models, and you can create an endpoint directly from that model object for quick testing.
A screenshot of the Amazon S3 web console showing the contents of an "output/" folder. It lists a single object named "model.tar.gz" (1.2 KB) with actions like Copy S3 URI, Download, Open, and Delete.
A screenshot of the Amazon SageMaker console showing a model page titled "kodekloud-house-prices-demo" with model settings, container details, S3 model data location, and network information. The page also shows action buttons (Create endpoint, Create batch transform job) and a large mouse cursor.
Model.create is great for rapid prototyping and one-off endpoints. For production tracking, reproducibility, and approval workflows, prefer the SageMaker Model Registry with Model.register.

3. Model Registry: create a Model Package Group and register a model version

The Model Registry stores model versions inside a Model Package Group and provides metadata, metrics, versioning, lineage, and approval workflows. Use the Boto3 SageMaker client to create a model package group, then call Model.register() to add a model version. Create the package group:
# Create a model package group using the low-level boto3 client
model_package_group_name = 'house-price-model-registry-demonstration'
model_package_group_description = 'KodeKloud model package group for house price prediction'

sagemaker_client = boto3.client('sagemaker')

try:
    sagemaker_client.create_model_package_group(
        ModelPackageGroupName=model_package_group_name,
        ModelPackageGroupDescription=model_package_group_description
    )
    print(f'Created Model Package Group: {model_package_group_name}')
except sagemaker_client.exceptions.ResourceInUse:
    print(f'Model Package Group {model_package_group_name} already exists.')
Register the model artifact into the registry as a model package version. Set an initial approval status (for example, PendingManualApproval) and attach any custom metadata you want to track.
# Register the model into the model registry
model_approval_status = "PendingManualApproval"
customer_metadata_properties = {"ModelType": "HousePricePrediction"}

model_package = model.register(
    content_types=["text/csv"],
    response_types=["text/csv"],
    inference_instances=["ml.t2.medium", "ml.m5.large"],
    transform_instances=["ml.m5.large"],
    model_package_group_name=model_package_group_name,
    approval_status=model_approval_status,
    customer_metadata_properties=customer_metadata_properties,
)

print(f"Model package version ARN: {model_package.model_package_arn}")
After registration, the version appears in SageMaker Studio → Model Registry under the specified Model Package Group with the approval status you supplied.
A screenshot of the Amazon SageMaker Model Registry "Version 1" overview showing a model training status and tabs for Overview/Activity/Lineage. The main panel displays a metrics table with entries like validation:mae, validation:mse, validation:r2 and their numeric values.
In the Model Registry UI you can inspect:
  • Metrics collected during training (MAE, MSE, R2, etc.),
  • Artifacts (training and validation datasets, model artifact S3 paths),
  • Hyperparameters used during training,
  • The container image associated with the model,
  • Activity feed (registration, approval, deployment events),
  • Lineage that links datasets, training jobs, and containers to the model.
A screenshot of an AWS SageMaker Studio model version overview displaying hyperparameters (epochs = 10, mini_batch_size = 32, predictor_type = regressor) with Training marked "Complete" and Deploy "Pending Approval." The left sidebar shows navigation items (Performance, Artifacts, Hyperparameters) and a large mouse cursor is visible.

4. Approve a model version (in the UI) and deploy the latest approved version

Once a model version is approved in the Model Registry UI (for example, change status from PendingManualApprovalApproved), you can programmatically find the latest approved version and deploy it.
Approving a model should follow your organization’s validation and governance processes. Only approve models that meet performance, fairness, and security requirements.
List the latest approved model packages in the package group (sorted by creation time) and select the most recent:
# List the latest approved model packages in the package group (descending by creation time)
response = sagemaker_client.list_model_packages(
    ModelPackageGroupName=model_package_group_name,
    ModelApprovalStatus='Approved',
    SortBy='CreationTime',
    SortOrder='Descending'
)

if not response.get('ModelPackageSummaryList'):
    raise RuntimeError('No approved model packages found.')

latest_approved_model_package_arn = response['ModelPackageSummaryList'][0]['ModelPackageArn']
print(f'Latest Approved Model Package ARN: {latest_approved_model_package_arn}')
Create a ModelPackage object from the approved ARN and deploy it to a real-time endpoint:
# Create a ModelPackage object and deploy it
model_package = ModelPackage(
    role=role,
    model_package_arn=latest_approved_model_package_arn,
    sagemaker_session=sagemaker_session
)

predictor = model_package.deploy(
    initial_instance_count=1,
    instance_type="ml.m5.large",
    endpoint_name="latest-house-price-model"
)
Deployment can take several minutes. Once deployed, the endpoint will appear under Endpoints in SageMaker Studio/Console.
Screenshot of the Amazon SageMaker Studio model version overview for a "House Price" model, showing container locations and available instance types. A "Deploy — Approved" panel is highlighted with a large cursor over the Deploy button.
Deploying a model created from a Model Registry package will also create a model entry under the legacy Models console (Inference → Models), since the deployed artifact is a managed model package.
A screenshot of the Amazon SageMaker "Models" console in a web browser showing two model entries (house-price-model-registry-demonstratio... and kodekloud-house-prices-demo) with the left navigation menu visible. A large black mouse cursor is shown near the center of the screen.
After deployment you can confirm the endpoint status:
A screenshot of the Amazon SageMaker Studio "Endpoints" page showing one deployed endpoint named "latest-house-price-model" with status "In service." The dark-themed UI includes a left navigation sidebar and a large mouse cursor hovering over the endpoint list.

Quick comparison: Model.create vs Model.register

ResourceUse CaseBenefits
Model.create (legacy model package)Rapid prototyping, one-off endpointsFast, minimal workflow to create a model package and deploy
Model.register + Model RegistryProduction model lifecycle, versioning, governanceVersioning, approval workflows, metrics, lineage, metadata, reproducibility

Summary

  • Model.create is a quick, legacy method to create model packages for prototyping and rapid testing.
  • Model.register combined with the SageMaker Model Registry is the recommended approach for production: it provides robust versioning, approval workflows, stored metrics, activity logs, and lineage for reproducibility.
  • After a model version is approved in the registry, you can programmatically fetch the latest approved package and deploy it as a real-time endpoint.
We will also explore different hosting options—real-time endpoints and batch transforms—and when to choose each approach.

Watch Video