Building Scalable Applications with AWS Lambda, Cloudflare Workers and the Serverless Framework
Introduction: The Serverless Revolution in Python
- Why This Book Exists
- Who This Book Is For
- The Two Platforms
- The Serverless Framework
- How to Read This Book
- What You Will Build
Chapter 1: The Serverless Mindset
- What Serverless Actually Means (and Does Not Mean)
- Why Python for Serverless
- AWS Lambda vs. Cloudflare Workers: A Platform Comparison
- The Serverless Framework: Philosophy and Architecture
- Your First serverless.yml: Anatomy of a Configuration File
- Variable Resolution
- Common Pitfalls
- Summary
Chapter 2: Setting Up Your Development Environment
- Installing Node.js and the Serverless Framework CLI
- Python Environment Management with venv and Poetry
- IDE Setup and Code Quality Tooling
- Local Development Tools
- Configuring Cloud Credentials
- Project Structure Conventions
- Deploying Your First Function
- Common Setup Pitfalls
- Summary
Chapter 3: AWS Lambda Deep Dive
- Lambda Runtime Configuration and Python Versions
- Environment Variables and Parameter Store Integration
- IAM Roles and Permissions: The Principle of Least Privilege
- VPC Configuration and Networking Considerations
- Lambda Layers for Dependency Sharing
- Advanced Handler Patterns and Custom Runtimes
- Lambda Execution Environment Lifecycle
- Summary
Chapter 4: Cloudflare Workers Deep Dive
- The Cloudflare Workers Runtime Model
- Python on Workers: Wrapping and Bundling with esbuild
- Environment Variables and Secrets in Workers
- Durable Objects for Stateful Computations
- Workers KV and R2 Storage Integration
- Custom Domains and Routing Rules
- Deploying Workers with the Serverless Framework
- Summary
Chapter 5: API Gateway and HTTP Services
- AWS API Gateway Integration Patterns
- Cloudflare Workers Route Configuration
- Custom Domains and SSL/TLS
- Request Parsing and Response Formatting in Python
- CORS, Error Handling and API Versioning
- Authentication Middleware Patterns
- Summary
Chapter 6: Event-Driven Architectures
- AWS Event Sources: SQS, SNS and EventBridge
- DynamoDB Streams and Change Data Capture
- Cloudflare Queues and Scheduled Events
- Building a Cross-Platform Event Pipeline
- Dead Letter Queues and Retry Strategies
- Idempotency Patterns for Reliable Processing
- Summary
Chapter 7: Testing Serverless Python Applications
- Unit Testing Lambda Functions and Workers Handlers
- Integration Testing with LocalStack and Wrangler
- Mocking External Services and Dependencies
- Contract Testing for API Endpoints
- Performance and Load Testing Strategies
- Test Infrastructure as Code
- Summary
Chapter 8: CI/CD Pipelines and Multi-Stage Deployments
- CI/CD with GitHub Actions for Serverless
- GitLab CI and Alternative Pipeline Systems
- Multi-Stage Deployment Configuration
- Canary Deployments and Traffic Shifting
- Rollback Strategies and Disaster Recovery
- Pipeline Security and Secrets Management
- Summary
Chapter 9: Security Hardening
- IAM Policies and Least Privilege Enforcement
- Secrets Management: SSM Parameter Store, Secrets Manager, Workers Secrets
- Web Application Firewall (WAF) Configuration
- Input Validation and Output Encoding
- Dependency Scanning and Supply Chain Security
- Compliance and Audit Considerations
- Summary
Chapter 10: Observability, Monitoring and Debugging
- Structured Logging Patterns in Python
- AWS CloudWatch Logs and Metrics
- AWS X-Ray Distributed Tracing
- Cloudflare Analytics and Error Tracking
- Custom Dashboards and Alerting
- Debugging Strategies: From Cold Starts to Timeouts
- Summary
Chapter 11: Performance Optimization and Cost Management
- Understanding and Mitigating Cold Starts
- Memory and Timeout Tuning Strategies
- Connection Pooling and HTTP Client Optimization
- Caching Patterns: Local, CDN and Distributed
- Cost Monitoring and Budget Alerts
- Reserved Concurrency and Provisioned Capacity
- Summary
Chapter 12: Production Patterns and Migration Strategies
- Migrating Monolithic Applications to Serverless
- Blue-Green Deployments in Serverless
- Feature Flags and Gradual Rollouts
- Multi-Region and Edge Computing Architectures
- Disaster Recovery and Business Continuity
- The Future of Serverless Python
- Summary
