Amazon SageMaker MLOps
When to Use
- Designing ML training and serving infrastructure on AWS SageMaker
- Building ML pipelines with SageMaker Pipelines (training → evaluation → deployment)
- Implementing model versioning with SageMaker Model Registry
- Monitoring models in production with SageMaker Model Monitor
- Optimizing training costs with Spot instances and managed checkpointing
- Preparing for AWS Certified Machine Learning Engineer Associate (MLA-C01) exam
Core Jobs
1. Training Job Configuration
| Option |
Cost |
Best For |
| On-Demand instances |
Full price |
Short jobs, time-critical, no interruption risk |
| Spot training |
Up to 90% savings |
Long batch jobs; must use checkpointing |
| SageMaker Training Warm Pools |
Reserve compute between runs |
Iterative development (reduces startup time) |
Spot training requirements:
- Must implement checkpointing (save model state periodically to S3)
- On interruption, SageMaker saves checkpoint; resumes from last checkpoint when capacity returns
- Checkpoint path:
s3://bucket/checkpoints/job-name/
- Training frameworks (TensorFlow, PyTorch, MXNet) have native checkpoint support
Managed Spot Training code:
estimator = Estimator(
...
use_spot_instances=True,
max_run=3600, # max total training time (seconds)
max_wait=7200, # max wait including interruptions
checkpoint_s3_uri="s3://bucket/checkpoints/",
checkpoint_local_path="/opt/ml/checkpoints"
)
Built-in algorithms vs custom containers:
| Approach |
Use Case |
Example |
| Built-in algorithms |
Common ML tasks, fast start |
XGBoost, Linear Learner, K-Means, BlazingText |
| Script mode |
Familiar framework (TF/PyTorch/sklearn), custom code |
Bring your own training script |
| Custom container |
Exotic runtime, custom dependencies |
Custom C++ inference, specialized research |
| Pre-trained model (Jumpstart) |
Fine-tune foundation models |
LLMs, BERT, ResNet |
2. Inference Endpoint Types
| Endpoint Type |
Latency |
Payload Size |
Use Case |
| Real-time endpoint |
Synchronous, milliseconds |
< 6MB |
Interactive APIs, recommendations, fraud detection |
| Serverless endpoint |
Cold start possible |
< 4MB (request), < 20MB (model) |
Infrequent traffic (cost savings, no idle cost) |
| Async endpoint |
Minutes (result to S3) |
Up to 1GB |
Large payloads, long processing (NLP, video) |
| Batch Transform |
Offline, hours |
Entire dataset |
Offline scoring, pre-computation, bulk inference |
Async endpoint: request queued in SQS; processing result written to S3; notification via SNS/EventBridge.
Batch Transform: no endpoint needed; input from S3; output to S3; best for periodic bulk scoring.
Multi-model endpoint (MME): host thousands of models on a single endpoint; SageMaker loads/unloads models from S3 to GPU/CPU memory dynamically. Cost-effective for many similar models.
Multi-container endpoint: run different models/containers on one endpoint; invoke a specific container. Use for A/B testing or ensemble inference.
3. SageMaker Pipelines (MLOps Workflow)
Supported step types:
| Step Type |
Purpose |
ProcessingStep |
Data preprocessing, feature engineering, evaluation |
TrainingStep |
Model training job |
TuningStep |
Hyperparameter optimization (HPO) |
TransformStep |
Batch inference |
RegisterModel |
Register model version in Model Registry |
ConditionStep |
Branch pipeline based on evaluation metrics |
CreateModelStep |
Create SageMaker model from training artifacts |
LambdaStep |
Invoke Lambda function (custom logic) |
ClarifyCheckStep |
Bias/explainability analysis |
Example pipeline flow:
ProcessingStep (feature engineering)
↓
TrainingStep (train XGBoost)
↓
ProcessingStep (evaluate on test set)
↓
ConditionStep (accuracy > 0.9?)
├── Yes → RegisterModel (Approved)
└── No → RegisterModel (Rejected)
SageMaker Pipelines vs Step Functions:
- Pipelines = ML-native; step types understand ML artifacts (models, datasets); experiment tracking built-in
- Step Functions = general workflow; use when integrating ML with non-ML AWS services
4. Model Registry
- Version ML models with metadata, metrics, and approval status
- Approval states: Pending (default) → Approved / Rejected
- CI/CD trigger: approved model version → EventBridge → CodePipeline → deploy to endpoint
- Cross-account: share model package groups across accounts (for separate dev/staging/prod accounts)
Workflow:
- Training pipeline registers new model version (status: Pending)
- Automatic evaluation → conditional approval or human review
- Approval → EventBridge event → CodePipeline deploys to staging endpoint
- Staging validation passes → deploy to production endpoint
5. Model Monitor
Continuously monitors deployed endpoint data for:
| Monitor Type |
What It Detects |
Baseline |
| Data quality |
Feature distribution drift (input data statistics change) |
Baseline from training data |
| Model quality |
Accuracy/precision drift (compare predictions vs ground truth) |
Baseline from training evaluation |
| Bias drift |
Fairness metric changes (demographic parity, etc.) |
Baseline from Clarify bias analysis |
| Feature attribution drift |
SHAP value changes (important features changing) |
Baseline from Clarify explainability analysis |
Setup requirements:
- Enable data capture on endpoint (captures request/response samples to S3)
- Generate baseline statistics from training data
- Schedule monitoring job (hourly, daily, etc.)
- CloudWatch alerts on constraint violations → SNS notification
6. SageMaker Feature Store
| Store Type |
Latency |
Backed By |
Best For |
| Online store |
Milliseconds |
In-memory cache |
Real-time inference (serving) |
| Offline store |
Seconds-minutes |
S3 (Parquet, Iceberg) |
Model training, batch queries |
Feature reuse: compute features once, store in Feature Store, reuse across multiple models and teams.
Point-in-time queries: offline store supports time-travel queries (get feature values as of specific timestamp) — prevents training/serving skew.
Key Concepts
- SageMaker Studio — unified web IDE: notebooks, experiments, pipelines, model registry, endpoints; replaces individual SageMaker interfaces
- SageMaker Experiments — track training runs, hyperparameters, metrics, artifacts; query to find best run
- SageMaker Clarify — bias detection and explainability (SHAP values) for training data and predictions
- SageMaker Debugger — capture tensors during training; detect training issues (vanishing gradients, overfitting)
- Hyperparameter Tuning (HPO) — Bayesian optimization or random search over defined hyperparameter ranges
- Model Dashboard — unified view of all models, endpoint health, monitor violations
- Inference Recommender — benchmark instance types for your model (right-sizing for cost/latency)
- SageMaker JumpStart — pre-trained models and solution templates (foundation models, computer vision, NLP)
Checklist
Output Format
- 🔴 Critical — Spot training without checkpointing (job restarts from scratch on interruption, wasting compute); no model versioning (cannot roll back; no approval workflow)
- 🟡 Warning — Real-time endpoint for large payload inference (use async); no Model Monitor (production drift undetected); all training on on-demand instances (significant cost savings missed)
- 🟢 Suggestion — Multi-model endpoint for many similar models (cost savings vs individual endpoints); SageMaker Inference Recommender for instance right-sizing; Feature Store for cross-team feature reuse
Exam Tips
- Spot training = up to 90% cost savings; must enable checkpointing for long jobs — SageMaker resumes from last checkpoint after interruption
- Async endpoint = for payloads > 6MB or processing > 60 seconds; results written to S3; poll or use SNS for completion notification
- Batch Transform = offline scoring of entire dataset; no endpoint required; input from S3, output to S3
- Model Monitor requires baseline from training data statistics; monitors for data drift in production (compare incoming request distributions)
- SageMaker Pipelines = NOT Step Functions; native ML pipeline service with ML-specific steps (ProcessingStep, TrainingStep, ConditionStep, RegisterModel)
- Feature Store: online (low-latency serving) + offline (S3-backed, for training) — same concept as Vertex AI Feature Store; online and offline stores are separate
- ConditionStep = branch pipeline based on evaluation metric threshold (if accuracy > 0.9 → approve model; else → reject)
- Multi-model endpoint (MME) = host thousands of models on one endpoint; SageMaker dynamically loads/evicts models from memory based on traffic
1---2name: sagemaker-mlops3description: Use when building ML training/serving pipelines on AWS SageMaker, implementing MLOps with SageMaker Pipelines and Model Registry, monitoring models in production, or optimizing training costs with Spot instances. Covers AWS MLA-C01 exam domains.4---56# Amazon SageMaker MLOps78## When to Use9- Designing ML training and serving infrastructure on AWS SageMaker10- Building ML pipelines with SageMaker Pipelines (training → evaluation → deployment)11- Implementing model versioning with SageMaker Model Registry12- Monitoring models in production with SageMaker Model Monitor13- Optimizing training costs with Spot instances and managed checkpointing14- Preparing for AWS Certified Machine Learning Engineer Associate (MLA-C01) exam1516## Core Jobs1718### 1. Training Job Configuration1920| Option | Cost | Best For |21|--------|------|---------|22| **On-Demand instances** | Full price | Short jobs, time-critical, no interruption risk |23| **Spot training** | Up to 90% savings | Long batch jobs; must use checkpointing |24| **SageMaker Training Warm Pools** | Reserve compute between runs | Iterative development (reduces startup time) |2526**Spot training requirements**:27- Must implement checkpointing (save model state periodically to S3)28- On interruption, SageMaker saves checkpoint; resumes from last checkpoint when capacity returns29- Checkpoint path: `s3://bucket/checkpoints/job-name/`30- Training frameworks (TensorFlow, PyTorch, MXNet) have native checkpoint support3132**Managed Spot Training code**:33```python34estimator = Estimator(35 ...36 use_spot_instances=True,37 max_run=3600, # max total training time (seconds)38 max_wait=7200, # max wait including interruptions39 checkpoint_s3_uri="s3://bucket/checkpoints/",40 checkpoint_local_path="/opt/ml/checkpoints"41)42```4344**Built-in algorithms vs custom containers**:4546| Approach | Use Case | Example |47|----------|---------|---------|48| **Built-in algorithms** | Common ML tasks, fast start | XGBoost, Linear Learner, K-Means, BlazingText |49| **Script mode** | Familiar framework (TF/PyTorch/sklearn), custom code | Bring your own training script |50| **Custom container** | Exotic runtime, custom dependencies | Custom C++ inference, specialized research |51| **Pre-trained model (Jumpstart)** | Fine-tune foundation models | LLMs, BERT, ResNet |5253### 2. Inference Endpoint Types5455| Endpoint Type | Latency | Payload Size | Use Case |56|--------------|---------|-------------|---------|57| **Real-time endpoint** | Synchronous, milliseconds | < 6MB | Interactive APIs, recommendations, fraud detection |58| **Serverless endpoint** | Cold start possible | < 4MB (request), < 20MB (model) | Infrequent traffic (cost savings, no idle cost) |59| **Async endpoint** | Minutes (result to S3) | Up to 1GB | Large payloads, long processing (NLP, video) |60| **Batch Transform** | Offline, hours | Entire dataset | Offline scoring, pre-computation, bulk inference |6162**Async endpoint**: request queued in SQS; processing result written to S3; notification via SNS/EventBridge.6364**Batch Transform**: no endpoint needed; input from S3; output to S3; best for periodic bulk scoring.6566**Multi-model endpoint (MME)**: host thousands of models on a single endpoint; SageMaker loads/unloads models from S3 to GPU/CPU memory dynamically. Cost-effective for many similar models.6768**Multi-container endpoint**: run different models/containers on one endpoint; invoke a specific container. Use for A/B testing or ensemble inference.6970### 3. SageMaker Pipelines (MLOps Workflow)7172**Supported step types**:7374| Step Type | Purpose |75|-----------|---------|76| `ProcessingStep` | Data preprocessing, feature engineering, evaluation |77| `TrainingStep` | Model training job |78| `TuningStep` | Hyperparameter optimization (HPO) |79| `TransformStep` | Batch inference |80| `RegisterModel` | Register model version in Model Registry |81| `ConditionStep` | Branch pipeline based on evaluation metrics |82| `CreateModelStep` | Create SageMaker model from training artifacts |83| `LambdaStep` | Invoke Lambda function (custom logic) |84| `ClarifyCheckStep` | Bias/explainability analysis |8586**Example pipeline flow**:87```88ProcessingStep (feature engineering)89 ↓90TrainingStep (train XGBoost)91 ↓92ProcessingStep (evaluate on test set)93 ↓94ConditionStep (accuracy > 0.9?)95 ├── Yes → RegisterModel (Approved)96 └── No → RegisterModel (Rejected)97```9899**SageMaker Pipelines vs Step Functions**:100- Pipelines = ML-native; step types understand ML artifacts (models, datasets); experiment tracking built-in101- Step Functions = general workflow; use when integrating ML with non-ML AWS services102103### 4. Model Registry104105- Version ML models with metadata, metrics, and approval status106- Approval states: **Pending** (default) → **Approved** / **Rejected**107- CI/CD trigger: approved model version → EventBridge → CodePipeline → deploy to endpoint108- Cross-account: share model package groups across accounts (for separate dev/staging/prod accounts)109110**Workflow**:1111. Training pipeline registers new model version (status: Pending)1122. Automatic evaluation → conditional approval or human review1133. Approval → EventBridge event → CodePipeline deploys to staging endpoint1144. Staging validation passes → deploy to production endpoint115116### 5. Model Monitor117118Continuously monitors deployed endpoint data for:119120| Monitor Type | What It Detects | Baseline |121|-------------|----------------|---------|122| **Data quality** | Feature distribution drift (input data statistics change) | Baseline from training data |123| **Model quality** | Accuracy/precision drift (compare predictions vs ground truth) | Baseline from training evaluation |124| **Bias drift** | Fairness metric changes (demographic parity, etc.) | Baseline from Clarify bias analysis |125| **Feature attribution drift** | SHAP value changes (important features changing) | Baseline from Clarify explainability analysis |126127**Setup requirements**:1281. Enable data capture on endpoint (captures request/response samples to S3)1292. Generate baseline statistics from training data1303. Schedule monitoring job (hourly, daily, etc.)1314. CloudWatch alerts on constraint violations → SNS notification132133### 6. SageMaker Feature Store134135| Store Type | Latency | Backed By | Best For |136|-----------|---------|----------|---------|137| **Online store** | Milliseconds | In-memory cache | Real-time inference (serving) |138| **Offline store** | Seconds-minutes | S3 (Parquet, Iceberg) | Model training, batch queries |139140**Feature reuse**: compute features once, store in Feature Store, reuse across multiple models and teams.141**Point-in-time queries**: offline store supports time-travel queries (get feature values as of specific timestamp) — prevents training/serving skew.142143## Key Concepts144145- **SageMaker Studio** — unified web IDE: notebooks, experiments, pipelines, model registry, endpoints; replaces individual SageMaker interfaces146- **SageMaker Experiments** — track training runs, hyperparameters, metrics, artifacts; query to find best run147- **SageMaker Clarify** — bias detection and explainability (SHAP values) for training data and predictions148- **SageMaker Debugger** — capture tensors during training; detect training issues (vanishing gradients, overfitting)149- **Hyperparameter Tuning (HPO)** — Bayesian optimization or random search over defined hyperparameter ranges150- **Model Dashboard** — unified view of all models, endpoint health, monitor violations151- **Inference Recommender** — benchmark instance types for your model (right-sizing for cost/latency)152- **SageMaker JumpStart** — pre-trained models and solution templates (foundation models, computer vision, NLP)153154## Checklist155156- [ ] Spot training enabled with checkpointing for long training jobs?157- [ ] Endpoint type matched to use case (real-time, async, batch, serverless)?158- [ ] SageMaker Pipelines defined for reproducible ML workflow (not ad-hoc notebooks)?159- [ ] Model Registry used for versioning and approval workflow?160- [ ] Data capture enabled on endpoint before setting up Model Monitor?161- [ ] Model Monitor baseline generated from training data statistics?162- [ ] Feature Store used for shared features across models (avoid feature duplication)?163- [ ] IAM execution roles for training jobs follow least-privilege principle?164165## Output Format166167- 🔴 **Critical** — Spot training without checkpointing (job restarts from scratch on interruption, wasting compute); no model versioning (cannot roll back; no approval workflow)168- 🟡 **Warning** — Real-time endpoint for large payload inference (use async); no Model Monitor (production drift undetected); all training on on-demand instances (significant cost savings missed)169- 🟢 **Suggestion** — Multi-model endpoint for many similar models (cost savings vs individual endpoints); SageMaker Inference Recommender for instance right-sizing; Feature Store for cross-team feature reuse170171## Exam Tips172173- **Spot training = up to 90% cost savings**; must enable checkpointing for long jobs — SageMaker resumes from last checkpoint after interruption174- **Async endpoint = for payloads > 6MB or processing > 60 seconds**; results written to S3; poll or use SNS for completion notification175- **Batch Transform = offline scoring of entire dataset**; no endpoint required; input from S3, output to S3176- **Model Monitor requires baseline** from training data statistics; monitors for data drift in production (compare incoming request distributions)177- **SageMaker Pipelines = NOT Step Functions**; native ML pipeline service with ML-specific steps (ProcessingStep, TrainingStep, ConditionStep, RegisterModel)178- **Feature Store: online (low-latency serving) + offline (S3-backed, for training)** — same concept as Vertex AI Feature Store; online and offline stores are separate179- **ConditionStep** = branch pipeline based on evaluation metric threshold (if accuracy > 0.9 → approve model; else → reject)180- **Multi-model endpoint (MME)** = host thousands of models on one endpoint; SageMaker dynamically loads/evicts models from memory based on traffic