Contents

Chapter 1

What's Included

This chapter covers the core features and capabilities of Serverless Patterns Collection.

What's Included

CloudFormation Templates (5)

TemplatePatternDescription
api-gateway-lambda.yamlSynchronous REST APIAPI Gateway + Lambda + DynamoDB with throttling, alarms, and X-Ray
event-driven-pipeline.yamlEvent-Driven PipelineEventBridge + SQS + Lambda with DLQ and event archival
fan-out-pattern.yamlFan-Out (One-to-Many)SNS + 3 SQS consumers with filter policies and dashboards
saga-orchestration.yamlSaga OrchestrationStep Functions + 7 Lambda functions with compensation chain
cqrs-event-sourcing.yamlCQRS + Event SourcingDynamoDB Streams + Lambda projector + separate read/write models

Lambda Functions (4)

FunctionPurposeLines
api_handler.pyREST API CRUD handler with validation, routing, correlation IDs~400
event_processor.pySQS batch processor with idempotency, partial failure reporting~300
saga_coordinator.pyStep Functions task handlers (4 steps + 3 compensations)~350
stream_processor.pyDynamoDB Streams projector for CQRS read model~350

Documentation (5)

DocumentContent
docs/architecture.mdReference architecture with Mermaid diagrams, cost model, deployment strategy
docs/patterns-catalog.md36 serverless patterns organized by category with trade-offs
docs/cost-optimization.mdLambda right-sizing, DynamoDB optimization, API Gateway savings
docs/security-considerations.mdOWASP Serverless Top 10, IAM best practices, security checklist
docs/deployment-guide.mdStep-by-step deployment, CI/CD integration, troubleshooting

Scripts (2)

ScriptPurpose
scripts/pattern_selector.pyInteractive tool to find the right pattern for your use case
scripts/cost_calculator.pyEstimate monthly costs for each pattern at any traffic level

Examples (3)

ExampleContent
examples/api-gateway-config.jsonAPI Gateway stage configuration with throttling per method
examples/event-bridge-rules.jsonEventBridge rule patterns with content-based filtering examples
examples/step-functions-definition.jsonExtended Step Functions state machine with parallel branches

Quick Start

1. Choose Your Pattern

bash
# Run the interactive pattern selector
python3 scripts/pattern_selector.py

# Or see all patterns at a glance
python3 scripts/pattern_selector.py --all

2. Estimate Costs

bash
# Compare all patterns at 1M requests/month
python3 scripts/cost_calculator.py --requests 1000000

# Full comparison across traffic levels
python3 scripts/cost_calculator.py --compare

3. Deploy

bash
# Package Lambda functions
cd functions/
zip -r ../lambda-package.zip *.py
aws s3 cp ../lambda-package.zip s3://your-bucket/lambda-package.zip

# Deploy the REST API pattern (example)
aws cloudformation deploy \
  --template-file cloudformation/api-gateway-lambda.yaml \
  --stack-name my-api-dev \
  --parameter-overrides Environment=dev ApiName=my-api \
  --capabilities CAPABILITY_NAMED_IAM

# Get the API URL
aws cloudformation describe-stacks \
  --stack-name my-api-dev \
  --query "Stacks[0].Outputs[?OutputKey=='ApiUrl'].OutputValue" \
  --output text

4. Test Locally

All Lambda functions include if __name__ == "__main__": blocks for local testing:

bash
# Test the API handler
python3 functions/api_handler.py

# Test the event processor
python3 functions/event_processor.py

# Test the saga coordinator
python3 functions/saga_coordinator.py

# Test the stream processor
python3 functions/stream_processor.py

Pattern Selection Guide

QuestionREST APIEvent PipelineFan-OutSagaCQRS
Need sync response?YesNoNoMaybePartial
Latency requirement?< 1s1-30s1-30sSecondsRead: low
Multiple consumers?No1MultipleNoSeparate
Multi-step transaction?NoNoNoYesNo
Audit trail needed?MaybeSomeNoYesYes
Team complexity budget?LowMediumMediumHighVery High
Chapter 2

Architecture Overview

Follow this guide to get Serverless Patterns Collection up and running in your environment.

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     API Layer                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚ REST API β”‚  β”‚ WebSocketβ”‚  β”‚ Scheduledβ”‚                    β”‚
β”‚  β”‚ (APIGW)  β”‚  β”‚ (APIGW)  β”‚  β”‚ (EventBr)β”‚                   β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚       β”‚     Compute Layer          β”‚                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚  Lambda  β”‚  β”‚  Lambda  β”‚  β”‚  Lambda  β”‚                    β”‚
β”‚  β”‚ (Handler)β”‚  β”‚(Processor)β”‚ β”‚  (Cron)  β”‚                    β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚       β”‚     Messaging Layer        β”‚                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚EventBridgβ”‚  β”‚   SQS    β”‚  β”‚   SNS    β”‚                    β”‚
β”‚  β”‚  (Bus)   β”‚  β”‚ (Queues) β”‚  β”‚ (Topics) β”‚                    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                  Orchestration Layer                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
β”‚  β”‚          Step Functions (Sagas)           β”‚                β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Storage Layer                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚ DynamoDB β”‚  β”‚ DynamoDB β”‚  β”‚    S3    β”‚                     β”‚
β”‚  β”‚ (Tables) β”‚  β”‚(Streams) β”‚  β”‚ (Objects)β”‚                    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

File Structure

serverless-patterns-collection/
β”œβ”€β”€ README.md                           # This file
β”œβ”€β”€ LICENSE                             # MIT License
β”‚
β”œβ”€β”€ cloudformation/                     # Infrastructure-as-Code templates
β”‚   β”œβ”€β”€ api-gateway-lambda.yaml         # Pattern 1: Synchronous REST API
β”‚   β”œβ”€β”€ event-driven-pipeline.yaml      # Pattern 2: Event-Driven Pipeline
β”‚   β”œβ”€β”€ fan-out-pattern.yaml            # Pattern 3: Fan-Out (One-to-Many)
β”‚   β”œβ”€β”€ saga-orchestration.yaml         # Pattern 4: Saga Orchestration
β”‚   └── cqrs-event-sourcing.yaml        # Pattern 5: CQRS + Event Sourcing
β”‚
β”œβ”€β”€ functions/                          # Lambda function implementations
β”‚   β”œβ”€β”€ api_handler.py                  # REST API handler (CRUD + CQRS)
β”‚   β”œβ”€β”€ event_processor.py             # SQS event processor (batch + DLQ)
β”‚   β”œβ”€β”€ saga_coordinator.py            # Saga steps + compensations
β”‚   └── stream_processor.py            # DynamoDB Streams projector
β”‚
β”œβ”€β”€ docs/                               # Deep-dive documentation
β”‚   β”œβ”€β”€ architecture.md                 # Reference architecture + diagrams
β”‚   β”œβ”€β”€ patterns-catalog.md             # 36 serverless patterns catalog
β”‚   β”œβ”€β”€ cost-optimization.md            # Cost optimization strategies
β”‚   β”œβ”€β”€ security-considerations.md      # Security best practices
β”‚   └── deployment-guide.md             # Deployment instructions
β”‚
β”œβ”€β”€ scripts/                            # Utility tools
β”‚   β”œβ”€β”€ pattern_selector.py             # Interactive pattern selection tool
β”‚   └── cost_calculator.py              # Serverless cost estimator
β”‚
└── examples/                           # Configuration examples
    β”œβ”€β”€ api-gateway-config.json         # API Gateway stage settings
    β”œβ”€β”€ event-bridge-rules.json         # EventBridge rule patterns
    └── step-functions-definition.json  # Extended state machine example

Requirements

  • AWS CLI v2 with configured credentials
  • Python 3.12+ (for Lambda functions and scripts)
  • AWS account with appropriate IAM permissions
  • No external Python packages required (stdlib only)
Chapter 3
πŸ”’ Available in full product

Cost Estimates

Chapter 4
πŸ”’ Available in full product

License

You’ve reached the end of the free preview

Get the full Serverless Patterns Collection and unlock everything.

All Chapters

Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.

Full Tool Suite

Access all interactive tools with complete data, all workload profiles, and the full scenario library.

Source Files

Downloadable source code, configuration files, and working examples from every chapter.

Lifetime Updates

Free updates for life. Every new chapter, tool, and improvement included.

Buy Now — $39 →
πŸ“¦ Free sample included — download another copy for the full product.
Serverless Patterns Collection v1.0.0 β€” Free Preview