Skip to content

safa0/mlops-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MLOps Infrastructure Template

A reusable AWS CDK template for building production-grade ML platforms. Provides end-to-end infrastructure for data ingestion, feature management, model training, real-time inference, and monitoring -- all defined as code.

Architecture Overview

The template deploys six CDK stacks that form a complete ML pipeline:

  1. DataPipelineStack -- S3 raw data bucket with lifecycle policies, Lambda for event-driven ingestion into Feature Store
  2. FeatureStoreStack -- SageMaker Feature Store (online + offline) with schema-as-code enforcement
  3. MLTrainingStack -- S3 model artifacts bucket, IAM roles for SageMaker training jobs
  4. MLServingStack -- SageMaker Inference Pipeline endpoint with data capture for monitoring
  5. InferenceApiStack -- API Gateway REST API with Lambda proxy for real-time predictions
  6. MonitoringStack -- CloudWatch alarms (7), dashboard, SNS alerting, Model Monitor baseline support

Data flows through the system as follows: raw data lands in S3, triggering a Lambda that extracts features and writes them to SageMaker Feature Store. The Feature Store serves both offline training (S3/Parquet) and online inference (real-time lookup). A SageMaker Inference Pipeline handles feature lookup and prediction in a single endpoint. API Gateway exposes a /predict endpoint backed by a thin Lambda.

Project Structure

architecture/          Architecture diagrams (Python -> PNG) and design decisions
code/                  Application code
  feature_schema.py    Single source of truth for all feature definitions
  feature_engineering.py  Domain-specific feature extraction logic
  lambda_function.py   Ingestion Lambda handler (S3 event -> Feature Store)
  inference_function.py   Inference Lambda handler (API -> SageMaker endpoint)
  preprocessing_handler.py  SageMaker preprocessing container code
  model_config.py      Model configuration and hyperparameters
  tests/               Unit and integration tests (pytest)
config/                AWS CDK infrastructure
  app.py               CDK app entry point
  cdk.json             CDK configuration and context
  stacks/              Stack definitions (6 stacks)
  tests/               CDK stack tests
docs/                  Security, monitoring, cost, and data documentation
sample-data/           Example data files for reference

Quick Start

1. Clone and install

git clone <this-repo-url> my-ml-project
cd my-ml-project
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt && pip install -r config/requirements.txt

2. Customize

  • Define your features in code/feature_schema.py
  • Implement extraction logic in code/feature_engineering.py
  • Update stack names in config/app.py

See SETUP.md for a detailed customization checklist.

3. Deploy

cd config
npx cdk bootstrap    # first time only
npx cdk deploy --all

What's Included

Infrastructure (CDK Stacks)

  • S3 buckets with encryption, versioning, lifecycle policies, and public access blocking
  • SageMaker Feature Store with online + offline stores
  • SageMaker training job IAM roles and model artifact storage
  • SageMaker Inference Pipeline with data capture
  • API Gateway REST API with API key authentication
  • CloudWatch alarms, dashboard, and SNS alerting
  • Least-privilege IAM roles scoped per service

Application Code

  • Schema-as-code pattern preventing feature drift across all components
  • Event-driven ingestion Lambda with validation
  • Thin inference Lambda with error mapping
  • SageMaker preprocessing handler for Feature Store lookup
  • Model monitoring baseline generation

Testing

  • Unit tests with moto (AWS mocking)
  • CDK stack synthesis tests
  • Feature schema validation tests
  • TDD workflow support

Documentation

  • Security checklist (AWS Well-Architected ML Lens)
  • Monitoring plan with runbooks
  • Cost estimates by environment (dev/staging/production)
  • Feature schema catalog
  • Architecture design decisions

Detailed Setup

See SETUP.md for prerequisites, step-by-step customization instructions, and common customization points.

About

Reusable MLOps template with AWS CDK: SageMaker Feature Store, Lambda ingestion, inference API, monitoring. 396 tests.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages