Skip to content
Kuza Ndoto Academy

Amazon SageMaker

Beginner → IntermediateChapter 6 · Page 22 of 304 min readUpdated 15 Nov 2026

Amazon SageMaker is AWS's platform for building, training and deploying your own machine learning models. When the ready-made AI services do not fit, because you need to predict something specific to your business from your own data, SageMaker provides notebooks, managed training on powerful machines and hosted endpoints that serve predictions.

A note on names

In late 2024 AWS reorganised its branding. The machine learning service this page describes is now called Amazon SageMaker AI, while the name "Amazon SageMaker" also covers a broader data and AI platform with SageMaker Unified Studio, which brings together analytics, data and ML tools. The core concepts below (Studio, training jobs, endpoints) are the same in both, and you will still see "SageMaker" used for all of it in tutorials and the console.

The ML lifecycle on SageMaker

Datain S3 PrepareStudio Trainingjob Modelin S3 Endpointhosted Your apppredicts Monitor predictions; retrain when data drifts
Figure 1. Data lives in S3. You explore and prepare it in Studio, a training job produces a model artefact in S3, and an endpoint serves it to your app. Monitoring closes the loop by triggering retraining.
ComponentWhat it does
SageMaker StudioA web-based IDE with JupyterLab and code editors, where you explore data and launch jobs
Processing jobsRun data cleaning and feature engineering scripts on managed instances
Training jobsStart instances, run your training script on data from S3, save the model to S3, then shut down
Model registryVersions and approves models before deployment
EndpointsHost a model behind an HTTPS API: real-time, serverless or asynchronous; batch transform for offline scoring
JumpStartPre-trained and foundation models you can deploy or fine-tune with a few clicks
CanvasNo-code model building for analysts
Pipelines and Model MonitorAutomate the workflow (MLOps) and watch for data drift

The key idea is that training jobs are temporary: SageMaker starts machines, runs your script, saves the result and shuts them down, so you pay only for the training time. Endpoints, by contrast, run until you delete them.

A small example: predicting delivery times

A Nairobi e-commerce shop wants to predict how many minutes a delivery will take from the distance, the number of items and the hour of the day. The steps follow The Machine Learning Workflow; SageMaker just runs them on managed infrastructure.

train.py: the training script. SageMaker passes data and output locations through environment variables:

import os

import joblib
import pandas as pd
from sklearn.ensemble import RandomForestRegressor


def model_fn(model_dir):
    """Used by the endpoint to load the trained model."""
    return joblib.load(os.path.join(model_dir, "model.joblib"))


if __name__ == "__main__":
    train_dir = os.environ["SM_CHANNEL_TRAIN"]
    model_dir = os.environ["SM_MODEL_DIR"]

    df = pd.read_csv(os.path.join(train_dir, "deliveries.csv"))
    X = df[["distance_km", "items", "hour"]]
    y = df["minutes"]

    model = RandomForestRegressor(n_estimators=100, random_state=42)
    model.fit(X, y)
    joblib.dump(model, os.path.join(model_dir, "model.joblib"))

In a Studio notebook: launch the training job and deploy. This uses the SageMaker Python SDK's estimator interface; major SDK versions have changed class names, so check the SageMaker Python SDK documentation for the version you install.

import sagemaker
from sagemaker.sklearn.estimator import SKLearn

role = sagemaker.get_execution_role()

estimator = SKLearn(
    entry_point="train.py",
    role=role,
    instance_type="ml.m5.large",
    instance_count=1,
    framework_version="1.2-1",
    py_version="py3",
)
estimator.fit({"train": "s3://kuza-ml-demo-2026/deliveries/"})

predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.m5.large")
print(predictor.predict([[5.2, 3, 18]]))   # 5.2 km, 3 items, 6 p.m.

predictor.delete_endpoint()   # stop paying for the endpoint
[41.73]

The prediction is an example; yours depends on your training data. While fit runs, the notebook streams the training job's logs, which are also saved in CloudWatch.

Once an endpoint exists, any application with permission can call it through boto3's sagemaker-runtime client using invoke_endpoint, so a web app or Lambda function can request predictions without the SageMaker SDK.

Choosing an endpoint type

  • Real-time: always-on instances for low-latency predictions. Billed per instance-hour.
  • Serverless: scales to zero when idle; good for occasional traffic, with some cold-start delay.
  • Asynchronous: queues large or slow requests and writes results to S3.
  • Batch transform: scores a whole dataset in S3 at once, with no endpoint left running.
Warning

SageMaker costs can grow fast. Real-time endpoints bill for every hour they exist, GPU instances are expensive, and Studio apps and notebook instances keep billing while running even if you close the browser tab. After practising: delete endpoints, stop Studio apps and spaces, and check the SageMaker console's dashboard for anything still running. Set a budget alert before you start.

SageMaker or something else?

  • Need common tasks like labels, sentiment or translation? Use the AI services.
  • Need a chatbot or text generation with a large language model? Start with Amazon Bedrock.
  • Need a custom model trained on your own tabular, image or time-series data? That is SageMaker's sweet spot.

Key points

  • SageMaker (now SageMaker AI for the ML service) covers the whole ML lifecycle: prepare, train, deploy, monitor.
  • Training jobs run your script on temporary managed instances and save the model to S3.
  • Endpoints serve predictions over HTTPS: real-time, serverless, asynchronous or batch.
  • Delete endpoints and stop Studio apps after use, because they bill while running.
Up next · AI & ML on AWSAmazon Bedrock & Generative AIUse foundation models through one managed API.
→

Tip: use the ← and → keys to move between pages.