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.
The template deploys six CDK stacks that form a complete ML pipeline:
- DataPipelineStack -- S3 raw data bucket with lifecycle policies, Lambda for event-driven ingestion into Feature Store
- FeatureStoreStack -- SageMaker Feature Store (online + offline) with schema-as-code enforcement
- MLTrainingStack -- S3 model artifacts bucket, IAM roles for SageMaker training jobs
- MLServingStack -- SageMaker Inference Pipeline endpoint with data capture for monitoring
- InferenceApiStack -- API Gateway REST API with Lambda proxy for real-time predictions
- 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.
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
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.txt2. 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- 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
- 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
- Unit tests with moto (AWS mocking)
- CDK stack synthesis tests
- Feature schema validation tests
- TDD workflow support
- Security checklist (AWS Well-Architected ML Lens)
- Monitoring plan with runbooks
- Cost estimates by environment (dev/staging/production)
- Feature schema catalog
- Architecture design decisions
See SETUP.md for prerequisites, step-by-step customization instructions, and common customization points.