CertNote/ Commute Study Notes
Roadmap
KOEN
CLF-C02 · FoundationalCloud Practitioner - Foundational
DVA-C02 · AssociateDeveloper - Associate
SAA-C03 · AssociateSolutions Architect - Associate
SOA-C02 · AssociateCloudOps Engineer - Associate
SAP-C02 · ProfessionalSolutions Architect - Professional
DOP-C02 · ProfessionalDevOps Engineer - Professional
Linux Master 2 · 2급KAIT Linux Master - Level 2
SCS-C03 · SpecialtySecurity - Specialty
Linux Master 1 · 1급KAIT Linux Master - Level 1
MLA-C01 · AssociateMachine Learning Engineer - Associate
  • Week 1
    • 1.The ML Lifecycle and the Role of the ML Engineer
    • 2.ML Problem Types and Evaluation Metric Basics
    • 3.AWS ML Stack at a Glance
    • 4.SageMaker Overview: Studio, Training/Inference, Built-in Algorithms
    • 5.Week 1 Comprehensive Review — ML Fundamentals & AWS Stack
  • Week 2
  • Week 3
  • Week 4
  • Week 5
  • Week 6
  • Week 7
    • 1.SageMaker Pipelines: Steps, DAG, Parameters, Condition Steps
    • 2.Model Registry & Model Governance: Model Package Groups, Approval Workflows, Version Management
    • 3.CI/CD for ML: SageMaker Projects, CodePipeline/CodeBuild Integration, Automated Deployment
    • 4.IaC & Workflow Orchestration: CloudFormation/CDK, Step Functions, EventBridge, Airflow (MWAA)
    • 5.Week 7 Synthesis: MLOps Review
  • Week 8
  • Week 9
  • Week 10
AIF-C01 · FoundationalAI Practitioner - Foundational
DEA-C01 · AssociateData Engineer - Associate
MLS-C01 · SpecialtyMachine Learning - Specialty
SQLD · 개발자SQL Developer (SQLD)

© CertNote · 주간랩스

  • About
  • Changelog
  • Contact
  • Terms
  • Privacy
← MLA-C01/Week 7/Day 3

Based on the MLA-C01 exam guide·Report an error

MLA-C01· AssociateWeek 7 · Day 3~27 min read

Day 3 - CI/CD for ML: SageMaker Projects, CodePipeline/CodeBuild Integration, Automated Deployment

📌 Key Takeaways

  • ML CI/CD automates two different triggers separately: code change → automatic retraining and registration (CI) and model approval → automatic deployment (CD).
  • SageMaker Projects provisions the repository, CodePipeline, CodeBuild, Model Registry, and EventBridge all at once through a Service Catalog template.
  • The standard structure is two pipelines: a Build pipeline (triggered by a code push) and a Deploy pipeline (triggered by model approval).
  • The standard CD chain: Registry approval → EventBridge → CodePipeline → CloudFormation deployment.
  • Deploying to staging and then placing a manual approval gate before going to production is the safe pattern that reduces the blast radius.

Applying CI/CD to ML

If every code change means a person reruns the pipeline in a notebook, clicks the approval button, and updates the endpoint by hand, it is still manual operation. Traditional software CI/CD is code push → build → test → deploy, but in ML there is an added axis of data and models.

CategoryTraditional software CI/CDML CI/CD
InputCodeCode + data
Build artifactBinary or imageTrained model artifact
TestingUnit and integration testsTests + model evaluation metric gate
Approval targetRelease candidateModel version (Registry)
What triggers a rerunCode changeCode change + data change, drift, schedule
  • CI (continuous integration): When the preprocessing or training script changes, automatically run the pipeline to train and evaluate, then register in the Registry.
  • CD (continuous deployment): When a model is approved, automatically deploy it to the staging and production endpoints.
  • You could wire this together by hand, but AWS lays down the whole skeleton at once with a template called SageMaker Projects.

💡 Related theory: The core idea of ML CI/CD is "make model deployment version-managed, automated, and rollback-capable like software deployment." Code, data, and models are all tracked, changes lead to automatic triggers, and when a problem occurs you must be able to go back to a previous version. In the exam, a flow of "Git commit → automatic retraining and deployment" points to the combination of SageMaker Projects + Code* services.

SageMaker Projects — The MLOps Template

SageMaker Projects provisions the CI/CD infrastructure that MLOps needs as a preconfigured template (Service Catalog based). When you create a project, the following are created all at once.

Resource createdRole
Source code repository (CodeCommit or Git)Preprocessing, training, and deployment code
Build pipeline (CodePipeline + CodeBuild)On a code change, runs the SageMaker Pipeline → registers the model
Deploy pipeline (CodePipeline)On model approval, deploys to the staging/production endpoints
Model Registry groupCatalog of trained model versions
EventBridge rulesTriggers that detect code push and model approval events
  • What you built by hand yesterday and the day before comes out bundled whole as a standard template.
  • The representative template is "model building, training, and deployment," which creates two repositories, one for build and one for deploy.

The Whole CI/CD Chain at a Glance

 ┌──────────── CI (code axis) ────────────┐
 Developer git push
      │
      ▼
 CodeCommit / Git repository
      │  (push event)
      ▼
 CodePipeline(Build) ──▶ CodeBuild (buildspec.yml)
                              │
                              ▼
                    SageMaker Pipeline run
          preprocessing → training → evaluation → ConditionStep
                              │ passed
                              ▼
                    RegisterModel → Model Registry
                    (PendingManualApproval)
 ─────────────────────────────────────────────────
 ┌──────────── CD (model axis) ────────────┐
      Reviewer changes it to Approved
                              │
                              ▼
              EventBridge "Model Package State Change"
                              │
                              ▼
                    CodePipeline(Deploy)
                              │
                ┌─────────────┴─────────────┐
                ▼                           │
      CloudFormation → staging endpoint     │
                ▼                           │
           automated tests pass             │
                ▼                           │
      ManualApproval action (human check) ──┘
                ▼
      CloudFormation → production endpoint

The key point is that the triggers above and below the dividing line are different. The one above is a code push, and the one below is model approval.

Two Pipelines: Build and Deploy

Comparison axisBuild pipelineDeploy pipeline
What it centers onCodeModel version
TriggerCode push to the repositoryRegistry approval (Approved) event
What it doesRuns the SageMaker Pipeline → training, evaluation, registrationCreates/updates the endpoint
Main execution toolCodeBuild (buildspec.yml)CloudFormation stack deployment
OutputA new model version in the RegistryStaging and production endpoints
Human involvementUsually noneManual approval gate just before production
CI/CD categoryCICD

1) Build (model build) pipeline — code-centric

  • A developer pushes the training code to the repository
  • CodePipeline detects the change and runs CodeBuild
  • CodeBuild runs the SageMaker Pipeline (preprocessing → training → evaluation → registration)
  • The resulting model is registered in the Model Registry as PendingManualApproval

2) Deploy (model deploy) pipeline — model-centric

  • The model in the Model Registry is changed to Approved
  • EventBridge detects the approval event and triggers the Deploy pipeline
  • The staging endpoint is deployed with CloudFormation → automated tests
  • When the manual approval gate is passed, the production endpoint is deployed

Roles of CodeCommit / CodeBuild / CodePipeline

Clearly separating what each service is responsible for is an exam point.

ServiceRoleEasily confused point
CodeCommitGit source repository (code version control)It only stores. It does not execute
CodeBuildBuild and test execution environment (commands defined in buildspec.yml)The only compute that actually runs commands
CodePipelineOrchestrator that links the stages (source → build → deploy flow)It does not build directly. It manages the order
CloudFormationDeploys infrastructure such as endpoints as codeThe executor of deployment. Also the unit of rollback
EventBridgeTriggers based on events (code push, model approval)Not a workflow but a start signal

CodeBuild's work is defined in buildspec.yml. For example, the build phase that runs a SageMaker Pipeline looks like this.

# buildspec.yml — defines the commands CodeBuild will run
version: 0.2
phases:
  install:
    runtime-versions:
      python: 3.11
    commands:
      - pip install -r requirements.txt
  build:
    commands:
      # On a code change, create/update the SageMaker Pipeline and run it
      - python pipelines/run_pipeline.py --upsert
      - python pipelines/run_pipeline.py --start

Automatic Deployment Trigger: Approval → EventBridge → Deployment

The heart of CD is the model approval event you learned yesterday. When the approval status changes in the Model Registry, EventBridge catches it and starts the Deploy pipeline.

import boto3
events = boto3.client("events")
 
# A rule that triggers the Deploy pipeline when the model approval status changes to Approved
events.put_rule(
    Name="trigger-deploy-on-approval",
    EventPattern="""{
      "source": ["aws.sagemaker"],
      "detail-type": ["SageMaker Model Package State Change"],
      "detail": {
        "ModelApprovalStatus": ["Approved"]
      }
    }""",
)

If you set this rule's target to the Deploy CodePipeline, deployment rolls automatically the moment a person approves the model. After staging validation and before production deployment, adding one more manual approval action is the safe pattern.

# CodePipeline stage example (conceptual): staging → manual approval → production
# 1. DeployStaging   (create the staging endpoint with CloudFormation)
# 2. ApprovalGate    (a person checks the staging results and approves)
# 3. DeployProd      (deploy the production endpoint)

The staged deployment of staging → manual approval → production in CI/CD follows the principle of "minimizing the blast radius." If you validate a new model in staging rather than putting it straight into production, and then pass it through a gate, defects are filtered out before they reach users. In the exam, a sentence like "to deploy automatically but safely while keeping control just before production" points to CodePipeline's manual approval action.

⚠️ Trap: "Automatic deployment on model approval" and "human confirmation just before production" are not contradictory. Approval happens twice — the first is the Registry's Approved (the decision to put the model into the deployment flow), and the second is CodePipeline's ManualApproval action (the decision to send it to production after seeing the staging validation results). Answer choices that lump these two into one are often wrong.

Direct Setup vs. SageMaker Projects

You can produce the same result by wiring CodePipeline, CodeBuild, and EventBridge together yourself without SageMaker Projects.

Comparison axisSageMaker ProjectsDirect setup
Speed of adoptionImmediate through template provisioningYou must wire services one by one
StandardizationReuse and governance across the organization through Service CatalogTends to become different for every team
FlexibilityCustomizable within the scope of the templateNo constraints
Integration with existing CI/CDA new skeleton is laid downEasy to attach to an existing pipeline
Exam keyword"Quickly standardize MLOps, template""Integrate with existing CI/CD, non-standard requirements"

Either way, what triggers retraining has to be designed separately. A code push alone cannot catch situations where the data changes.

Retraining triggerImplementationSuitable situation
Code changeRepository push → Build pipelineWhen you changed the algorithm or feature logic
Regular scheduleEventBridge cron ruleServices where data accumulates steadily
New data arrivalS3 event → EventBridgeWhen batches arrive irregularly
Quality degradation detectedMonitoring alarm → pipeline runWhen performance dropped because of drift

When CI/CD Goes Wrong: Symptom → Cause → Action

SymptomCommon causeAction
You pushed code but nothing happensSource stage branch mismatch, trigger disabledCheck the pipeline's source branch and detection settings
You approved but the Deploy pipeline does not runEventBridge pattern typo, target not connected, rule disabledInspect the event pattern, target, and rule state
CodeBuild fails as soon as it startsbuildspec.yml location or syntax error, runtime version mismatchCheck the buildspec path at the repository root and the phase syntax
The build is denied when creating a SageMaker jobThe CodeBuild role lacks SageMaker permissions or iam:PassRoleGrant the build role PassRole on the target execution role
Staging works but production does not go outWaiting at the manual approval actionSet the approvers and notification targets, then approve
The deployment stack fails midway and rolls backEndpoint configuration error, insufficient capacity, name collisionCheck the failed resource in the CloudFormation event log
A wrong model went to productionThe status was set straight to Approved at registrationRegister as PendingManualApproval + restore the review gate
Rollback takes a long timeThe previous version's information is not managed separatelyRedeploy using the Registry's previous approved version ARN

CI/CD failures are mostly one of three: trigger, permission, or definition. If nothing happens, it is the trigger; if it starts but is denied midway, it is permissions; if it runs to the end but the result is wrong, it is a definition (buildspec, template) problem. Narrowing down in this order means you do not have to dig through all the logs.

Tomorrow we compare IaC, which manages the very infrastructure that supports this deployment as code, with orchestrators that reach beyond SageMaker.

📖 Glossary

  • CI (continuous integration): The stage that automatically runs through training and evaluation when code changes and registers the resulting model.
  • CD (continuous deployment): The stage that pushes an approved model all the way to the endpoint without human hands.
  • SageMaker Projects: A feature that lays down the MLOps repository, pipelines, Registry, and triggers all at once with a single template.
  • Service Catalog: An AWS service that collects organization-approved infrastructure templates and makes people create things only the standard way. It is the foundation of Projects.
  • Build pipeline: The pipeline that starts with a code push and goes as far as training and registering the model.
  • Deploy pipeline: The pipeline that starts with model approval and deploys the endpoint.
  • buildspec.yml: A file that states which commands CodeBuild runs and in what order.
  • ManualApproval action: A stopping point in the middle of CodePipeline that moves on only when a person presses approve.
  • EventBridge rule: A routing rule saying "when this event arrives, send it there." The trigger of deployment automation.
  • Blast radius: The extent of damage when a problem erupts. The reason for going through staging is to reduce this.

📝 Practice Questions

Click a choice to reveal the answer and explanation.

Question 1

An ML team wants to provision the source repositories, build/deploy pipelines, and Model Registry needed for MLOps all at once from a preconfigured template. What is most suitable?

Question 2

In the standard SageMaker Projects structure, which pipeline does a "code push" trigger and which does a "model approval" trigger?

Question 3

Which file defines the commands CodeBuild actually runs (dependency installation, pipeline execution, etc.)?

Question 4

You want to automatically start a deployment pipeline when a model changes to Approved in the Registry. Which combination of services handles event detection and triggering?

Question 5

You want to automatically deploy a new model to production, but have a person take control once, after staging validation and right before it goes to production. What is the most appropriate method?

PreviousModel Registry & Model Governance: Model Package Groups, Approval Workflows, Version ManagementWeek 7 · Day 2Next IaC & Workflow Orchestration: CloudFormation/CDK, Step Functions, EventBridge, Airflow (MWAA)Week 7 · Day 4

Official references

  • MLA-C01 official exam page(opens in a new tab)
  • Amazon SageMaker AI documentation(opens in a new tab)
  • AWS CodePipeline documentation(opens in a new tab)
  • AWS CodeBuild documentation(opens in a new tab)
  • Amazon EventBridge documentation(opens in a new tab)
  • AWS CloudFormation documentation(opens in a new tab)

On this page

  • Key Takeaways
  • Applying CI/CD to ML
  • SageMaker Projects — The MLOps Template
  • The Whole CI/CD Chain at a Glance
  • Two Pipelines: Build and Deploy
  • Roles of CodeCommit / CodeBuild / CodePipeline
  • Automatic Deployment Trigger: Approval → EventBridge → Deployment
  • Direct Setup vs. SageMaker Projects
  • When CI/CD Goes Wrong: Symptom → Cause → Action
  • Glossary
  • Practice Questions