By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
CI/CD for ML automates the build, test, and deploy stages of machine learning models—just like software CI/CD, but with extra steps for data validation, model training, evaluation, and inference deployment. In AWS, this is done using SageMaker Pipelines (ML-specific workflows), CodePipeline (orchestration), and CloudFormation (infrastructure-as-code).
Real-world scenario:A fintech company retrains its fraud detection model weekly using new transaction data. They use SageMaker Pipelines to automate data preprocessing, model training, and A/B testing of the new model against the old one. CodePipeline triggers the pipeline when new data lands in S3, and CloudFormation deploys the updated endpoint with zero downtime.
SageMaker Pipelines AWS’s ML-specific workflow orchestrator (like Airflow but native to SageMaker). Defines steps for data prep, training, evaluation, and deployment. Uses Python SDK or JSON/YAML for pipeline definitions.
CodePipeline AWS’s CI/CD service for automating software (and ML) release workflows. Triggers pipelines on code commits, S3 uploads, or manual approvals. Integrates with CodeBuild (for running tests) and CodeDeploy (for deployments).
CloudFormation AWS’s infrastructure-as-code (IaC) service. Defines AWS resources (SageMaker endpoints, IAM roles, S3 buckets) in YAML/JSON templates. Enables repeatable, version-controlled deployments.
SageMaker Projects A pre-built CI/CD template for ML in SageMaker. Combines SageMaker Pipelines, CodePipeline, and CloudFormation into a single, reusable project. Includes model registry, approval gates, and automated rollbacks.
Model Registry A central catalog in SageMaker to track model versions, metadata, and approval status. Used in pipelines to promote models from "staging" to "production" after validation.
Processing Jobs SageMaker’s managed compute for data preprocessing, feature engineering, or model evaluation. Runs in isolated containers (no need to manage EC2 instances).
Approval Gates Manual or automated checkpoints in CodePipeline (e.g., "Approve model before deployment"). Critical for governance and compliance in regulated industries (e.g., healthcare, finance).
Canary Deployment A gradual rollout strategy where a new model version serves a small % of traffic before full deployment. Reduces risk of bad deployments. Supported in SageMaker endpoints via traffic splitting.
Infrastructure-as-Code (IaC) The practice of defining cloud resources in code (e.g., CloudFormation, Terraform). Ensures consistent, reproducible environments for ML pipelines.
Artifact Store An S3 bucket where SageMaker Pipelines store outputs (e.g., trained models, evaluation reports). Required for reproducibility and auditing.
EventBridge (CloudWatch Events) AWS’s event bus for triggering pipelines based on events (e.g., "New data in S3," "Model drift detected"). Used to automate retraining.
SageMaker Model Monitor Detects data drift, feature skew, or prediction anomalies in production. Can trigger retraining pipelines via EventBridge.
sagemaker.workflow
Example: python from sagemaker.workflow.pipeline import Pipeline pipeline = Pipeline( name="FraudDetectionPipeline", steps=[processing_step, training_step, evaluation_step, condition_step] )
python from sagemaker.workflow.pipeline import Pipeline pipeline = Pipeline( name="FraudDetectionPipeline", steps=[processing_step, training_step, evaluation_step, condition_step] )
Store Pipeline Definition in CodeCommit/GitHub
Example CloudFormation snippet for a SageMaker endpoint: yaml Resources: FraudDetectionEndpoint: Type: AWS::SageMaker::Endpoint Properties: EndpointConfigName: !Ref EndpointConfig
yaml Resources: FraudDetectionEndpoint: Type: AWS::SageMaker::Endpoint Properties: EndpointConfigName: !Ref EndpointConfig
Set Up CodePipeline
pytest
Add an approval gate before deployment (e.g., "Approve model for production").
Automate Triggers
Use EventBridge to trigger the pipeline when:
PutObject
ModelPackageStateChange
Deploy with CloudFormation
Example CLI command: bash aws cloudformation deploy --template-file pipeline.yaml --stack-name FraudDetectionStack
bash aws cloudformation deploy --template-file pipeline.yaml --stack-name FraudDetectionStack
Monitor and Roll Back
SageMaker Pipelines vs. Step Functions vs. Airflow
Key Constraints
CodePipeline has a 1-year execution limit for pipelines. For long-running ML jobs (e.g., training LLMs), use SageMaker Pipelines with manual approvals.
Tricky Scenarios
Question: "A team needs to automate model retraining when new data arrives in S3. Which AWS service should trigger the pipeline?"
Cost Optimization
Answer: SageMaker Pipelines + CodePipeline + CloudFormation.
Question: "A data scientist accidentally deployed a faulty model to production. The team wants to prevent this in the future. What should they implement?"
Answer: Approval gates in CodePipeline + Model Registry.
Question: "A team uses SageMaker Pipelines for training but needs to run a custom Python script for data validation before training. Which SageMaker feature should they use?"
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.