← Back to all products
$39
Serverless Patterns Collection
30+ serverless architecture patterns with Lambda/Functions implementations, event-driven designs, and cost optimization.
JSONPythonYAMLMarkdownTerraformAWSCI/CD
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 27 files
serverless-patterns-collection/
├── LICENSE
├── README.md
├── cloudformation/
│ ├── api-gateway-lambda.yaml
│ ├── cqrs-event-sourcing.yaml
│ ├── event-driven-pipeline.yaml
│ ├── fan-out-pattern.yaml
│ └── saga-orchestration.yaml
├── docs/
│ ├── architecture.md
│ ├── cost-optimization.md
│ ├── deployment-guide.md
│ ├── patterns-catalog.md
│ └── security-considerations.md
├── examples/
│ ├── api-gateway-config.json
│ ├── event-bridge-rules.json
│ └── step-functions-definition.json
├── free-sample.zip
├── functions/
│ ├── api_handler.py
│ ├── event_processor.py
│ ├── saga_coordinator.py
│ └── stream_processor.py
├── guide/
│ ├── 01_what-s-included.md
│ ├── 02_architecture-overview.md
│ ├── 03_cost-estimates.md
│ └── 04_license.md
├── index.html
└── scripts/
├── cost_calculator.py
└── pattern_selector.py
📖 Documentation Preview README excerpt
Serverless Patterns Collection
Production-ready AWS serverless architecture patterns with CloudFormation templates, Lambda implementations, and comprehensive documentation.
A curated collection of 5 core serverless patterns (with 30+ pattern variations documented) that solve the most common distributed systems challenges on AWS. Each pattern includes deployable infrastructure-as-code, working Lambda functions, and deep-dive documentation on architecture decisions, cost optimization, and security.
What's Included
CloudFormation Templates (5)
| Template | Pattern | Description |
|---|---|---|
api-gateway-lambda.yaml | Synchronous REST API | API Gateway + Lambda + DynamoDB with throttling, alarms, and X-Ray |
event-driven-pipeline.yaml | Event-Driven Pipeline | EventBridge + SQS + Lambda with DLQ and event archival |
fan-out-pattern.yaml | Fan-Out (One-to-Many) | SNS + 3 SQS consumers with filter policies and dashboards |
saga-orchestration.yaml | Saga Orchestration | Step Functions + 7 Lambda functions with compensation chain |
cqrs-event-sourcing.yaml | CQRS + Event Sourcing | DynamoDB Streams + Lambda projector + separate read/write models |
Lambda Functions (4)
| Function | Purpose | Lines |
|---|---|---|
api_handler.py | REST API CRUD handler with validation, routing, correlation IDs | ~400 |
event_processor.py | SQS batch processor with idempotency, partial failure reporting | ~300 |
saga_coordinator.py | Step Functions task handlers (4 steps + 3 compensations) | ~350 |
stream_processor.py | DynamoDB Streams projector for CQRS read model | ~350 |
Documentation (5)
| Document | Content |
|---|---|
docs/architecture.md | Reference architecture with Mermaid diagrams, cost model, deployment strategy |
docs/patterns-catalog.md | 36 serverless patterns organized by category with trade-offs |
docs/cost-optimization.md | Lambda right-sizing, DynamoDB optimization, API Gateway savings |
docs/security-considerations.md | OWASP Serverless Top 10, IAM best practices, security checklist |
docs/deployment-guide.md | Step-by-step deployment, CI/CD integration, troubleshooting |
Scripts (2)
| Script | Purpose |
|---|---|
scripts/pattern_selector.py | Interactive tool to find the right pattern for your use case |
scripts/cost_calculator.py | Estimate monthly costs for each pattern at any traffic level |
Examples (3)
| Example | Content |
|---|---|
examples/api-gateway-config.json | API Gateway stage configuration with throttling per method |
examples/event-bridge-rules.json | EventBridge rule patterns with content-based filtering examples |
examples/step-functions-definition.json | Extended Step Functions state machine with parallel branches |
Quick Start
1. Choose Your Pattern
# Run the interactive pattern selector
python3 scripts/pattern_selector.py
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
functions/api_handler.py
"""
Serverless REST API Handler — Lambda Function for API Gateway Integration
This module implements a production-ready Lambda handler for REST API operations.
It demonstrates best practices for:
- Structured logging with correlation IDs for distributed tracing
- Input validation with descriptive error messages
- DynamoDB single-table design with composite keys
- Proper HTTP response formatting for API Gateway proxy integration
- Idempotency for safe retries
- Cold start optimization techniques
Architecture:
API Gateway (REST) -> Lambda (this handler) -> DynamoDB
Usage:
Deploy with the api-gateway-lambda.yaml CloudFormation template.
The handler entry point is `handler(event, context)`.
Environment Variables:
TABLE_NAME: DynamoDB table name (set by CloudFormation)
ENVIRONMENT: Deployment environment (dev/staging/prod)
LOG_LEVEL: Logging level (DEBUG/INFO/WARNING/ERROR)
"""
from __future__ import annotations
import json
import logging
import os
import time
import uuid
from datetime import datetime, timezone
from typing import Any
# ─── Configuration ────────────────────────────────────────────
# Read configuration from environment variables set by CloudFormation.
# Using os.environ.get() with defaults makes local testing easier.
TABLE_NAME = os.environ.get("TABLE_NAME", "local-dev-table")
ENVIRONMENT = os.environ.get("ENVIRONMENT", "dev")
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
# ─── Logging Setup ────────────────────────────────────────────
# Configure structured logging. In production, use JSON format
# so CloudWatch Insights can parse and query log fields.
logger = logging.getLogger(__name__)
logger.setLevel(getattr(logging, LOG_LEVEL, logging.INFO))
def _json_serial(obj: Any) -> str:
# ... 517 more lines ...