Moving machine learning models from Jupyter notebooks to production is one of the biggest challenges data science teams face. AWS SageMaker Pipelines provides a robust framework for building end-to-end ML workflows, but the documentation can be overwhelming.
In this guide, I'll share the approach I've used to help multiple companies build production MLOps platforms.
Why SageMaker Pipelines?
Before diving in, let's understand when SageMaker Pipelines makes sense:
Good fit:
Consider alternatives if:
Core Components
A production SageMaker Pipeline typically includes:
Step 1: Setting Up Your Pipeline Structure
Here's the basic structure I recommend:
from sagemaker.workflow.pipeline import Pipeline
from sagemaker.workflow.steps import ProcessingStep, TrainingStep
from sagemaker.workflow.conditions import ConditionGreaterThan
from sagemaker.workflow.condition_step import ConditionStep
# Define your pipeline
pipeline = Pipeline(
name="my-ml-pipeline",
parameters=[
processing_instance_type,
training_instance_type,
model_approval_status,
],
steps=[
processing_step,
training_step,
evaluation_step,
condition_step,
],
)
Step 2: Data Processing
Use SageMaker Processing for data preparation:
from sagemaker.processing import ScriptProcessor
processor = ScriptProcessor(
role=role,
image_uri=processing_image,
instance_type="ml.m5.xlarge",
instance_count=1,
)
processing_step = ProcessingStep(
name="PreprocessData",
processor=processor,
inputs=[...],
outputs=[...],
code="preprocess.py",
)
Best Practice: Keep processing scripts idempotent and parameterized. This makes debugging much easier.
Step 3: Model Training
Configure training with appropriate instance types:
from sagemaker.estimator import Estimator
estimator = Estimator(
image_uri=training_image,
role=role,
instance_count=1,
instance_type="ml.m5.2xlarge",
output_path=f"s3://{bucket}/models",
hyperparameters={
"epochs": 10,
"learning_rate": 0.001,
},
)
training_step = TrainingStep(
name="TrainModel",
estimator=estimator,
inputs={"train": training_input},
)
Best Practice: Use Spot training for non-time-sensitive jobs—save up to 70% on training costs.
Step 4: Model Evaluation and Gating
Automatically evaluate models and gate deployment:
from sagemaker.workflow.conditions import ConditionGreaterThan
from sagemaker.workflow.condition_step import ConditionStep
condition = ConditionGreaterThan(
left=JsonGet(
step_name="EvaluateModel",
property_file=evaluation_report,
json_path="metrics.accuracy.value"
),
right=0.8, # Minimum accuracy threshold
)
condition_step = ConditionStep(
name="CheckModelAccuracy",
conditions=[condition],
if_steps=[register_step, deploy_step],
else_steps=[notify_failure_step],
)
Step 5: Model Registry
Register approved models for governance:
from sagemaker.workflow.model_step import ModelStep
from sagemaker.model import Model
model = Model(
image_uri=inference_image,
model_data=training_step.properties.ModelArtifacts.S3ModelArtifacts,
role=role,
)
register_step = ModelStep(
name="RegisterModel",
step_args=model.register(
model_package_group_name="my-model-group",
approval_status="PendingManualApproval",
),
)
Infrastructure as Code
Always define your pipelines with Terraform:
resource "aws_sagemaker_pipeline" "ml_pipeline" {
pipeline_name = "my-ml-pipeline"
pipeline_display_name = "My ML Pipeline"
role_arn = aws_iam_role.sagemaker_role.arn
pipeline_definition = jsonencode({
// Pipeline definition
})
}
Monitoring and Observability
Set up comprehensive monitoring:
Common Pitfalls to Avoid
Conclusion
SageMaker Pipelines provides a solid foundation for production MLOps, but success requires thoughtful architecture. Start simple, automate everything, and iterate based on your team's needs.
Building an MLOps platform? Let's discuss your requirements.

