0Pricing
Learn AI with Python · Lesson

Cloud Deployment: AWS SageMaker

SageMaker Model, EndpointConfig, Endpoint, real-time inference, batch transform.

Cloud Deployment: AWS SageMaker is a free Learn AI with Python lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why SageMaker

Amazon SageMaker is a managed service for training and deploying ML models. Instead of provisioning servers and load balancers yourself, you describe a model and SageMaker stands up a scalable HTTPS endpoint behind the scenes.

The Three Ingredients

A SageMaker deployment needs three things:

  • A container image_uri (your serving image in ECR or a built-in framework image)
  • The trained weights as model_data, a tar.gz in S3
  • An IAM role granting SageMaker access to those resources

Defining a Model

The sagemaker.Model object ties the container image to the model artifact in S3.

import sagemaker
from sagemaker.model import Model

model = Model(
    image_uri="123456789012.dkr.ecr.us-east-1.amazonaws.com/my-model:latest",
    model_data="s3://my-bucket/models/model.tar.gz",
    role="arn:aws:iam::123456789012:role/SageMakerRole",
)

What is in model.tar.gz

SageMaker downloads and extracts model_data into /opt/ml/model inside the container at startup. Your serving code reads weights from there. The archive typically contains the saved model file plus any preprocessing assets.

# model.tar.gz contents
# model.pt
# tokenizer.json
# config.json

Deploying a Real-Time Endpoint

model.deploy launches one or more instances behind a persistent HTTPS endpoint. You pick the instance_type and the initial instance count.

predictor = model.deploy(
    initial_instance_count=1,
    instance_type="ml.m5.xlarge",
    endpoint_name="my-model-endpoint",
)

Choosing an Instance Type

Instance type controls cost and latency:

  • ml.m5.* general-purpose CPU, cheap for small models
  • ml.c5.* compute-optimized
  • ml.g4dn.* / ml.g5.* GPU for deep learning inference

Match the instance to the model: a GPU is wasted on a tiny scikit-learn model.

Calling predict()

Once deployed, predictor.predict() sends a payload to the endpoint and returns the inference result. SageMaker serializes the request and routes it to a live instance.

result = predictor.predict({
    "instances": [[5.1, 3.5, 1.4, 0.2]]
})
print(result)

Cleaning Up Endpoints

Real-time endpoints bill per second while running. Always delete endpoints you no longer need, or you will accrue charges even with zero traffic.

predictor.delete_endpoint()

Batch Transform for Offline Jobs

For scoring a large dataset once (not low-latency serving), use batch transform. SageMaker spins up instances, processes an entire S3 dataset, writes results back to S3, then shuts the instances down. No persistent endpoint, no idle cost.

Running a Batch Transform

You create a transformer from the model and point it at input data in S3.

transformer = model.transformer(
    instance_count=1,
    instance_type="ml.m5.xlarge",
    output_path="s3://my-bucket/predictions/",
)
transformer.transform(
    data="s3://my-bucket/input/batch.csv",
    content_type="text/csv",
)
transformer.wait()

Real-Time vs Batch

Choose based on the workload:

  • Real-time endpoint: continuous, low-latency requests (e.g. a recommendation API)
  • Batch transform: periodic scoring of large datasets (e.g. nightly churn predictions)

Batch is far cheaper when you do not need instant responses.

Quick Check

When should you use SageMaker batch transform instead of a real-time endpoint?

Recap

You deployed a model to AWS SageMaker:

  • sagemaker.Model binds an image_uri to model_data in S3
  • model.deploy creates a real-time endpoint on a chosen instance_type
  • predictor.predict() sends inference requests
  • Batch transform handles large offline workloads cheaply
  • Always delete idle endpoints to avoid charges

Frequently asked questions

Is the “Cloud Deployment: AWS SageMaker” lesson free?

Yes — the full text of “Cloud Deployment: AWS SageMaker” is free to read here on the web, and the Learn AI with Python course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.

What will I learn in “Cloud Deployment: AWS SageMaker”?

SageMaker Model, EndpointConfig, Endpoint, real-time inference, batch transform. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn AI with Python?

No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Cloud Deployment: AWS SageMaker” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn AI with Python lesson?

Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Containerizing ML Models with Docker
  2. Cloud Deployment: AWS SageMaker
  3. High-Performance Serving with Triton Inference Server
  4. Scaling and Auto-Scaling Model Endpoints
← Back to Learn AI with Python