Leanpub Header

Skip to main content

Serverless Python in Production

Building Scalable Applications with AWS Lambda, Cloudflare Workers, and the Serverless Framework

This book is 100% completeLast updated on 2026-07-16

Deploy Python applications without managing servers. This practical guide takes you from your first serverless function to production-ready architectures on AWS Lambda and Cloudflare Workers using the Serverless Framework. Through real-world examples, proven deployment patterns, and hands-on guidance, you will learn how to build scalable, secure, and cost-effective applications with confidence.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
188
Pages
About

About

About the Book

This book teaches you how to build, test, deploy, and operate production-grade Python applications on two of the most powerful serverless platforms available today: AWS Lambda and Cloudflare Workers. Using the Serverless Framework as your deployment tool, you will learn everything from writing your first function to architecting complex event-driven systems with comprehensive observability, security hardening, and cost optimization. Every chapter includes working code examples, real configuration files, and expert guidance drawn from production deployments. Whether you are a Python developer exploring serverless for the first time or an experienced engineer looking to master cross-platform serverless architecture, this book is your complete reference.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 400 engineers and researchers from Ukraine, Belarus and Russia. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

Building Scalable Applications with AWS Lambda, Cloudflare Workers, and the Serverless Framework

Introduction: The Serverless Revolution in Python

  1. Why This Book Exists
  2. Who This Book Is For
  3. The Two Platforms
  4. The Serverless Framework
  5. How to Read This Book
  6. What You Will Build

Chapter 1: The Serverless Mindset

  1. What Serverless Actually Means (and Does Not Mean)
  2. Why Python for Serverless
  3. AWS Lambda vs. Cloudflare Workers: A Platform Comparison
  4. The Serverless Framework: Philosophy and Architecture
  5. Your First serverless.yml: Anatomy of a Configuration File
  6. Variable Resolution
  7. Common Pitfalls
  8. Summary

Chapter 2: Setting Up Your Development Environment

  1. Installing Node.js and the Serverless Framework CLI
  2. Python Environment Management with venv and Poetry
  3. IDE Setup and Code Quality Tooling
  4. Local Development Tools
  5. Configuring Cloud Credentials
  6. Project Structure Conventions
  7. Deploying Your First Function
  8. Common Setup Pitfalls
  9. Summary

Chapter 3: AWS Lambda Deep Dive

  1. Lambda Runtime Configuration and Python Versions
  2. Environment Variables and Parameter Store Integration
  3. IAM Roles and Permissions: The Principle of Least Privilege
  4. VPC Configuration and Networking Considerations
  5. Lambda Layers for Dependency Sharing
  6. Advanced Handler Patterns and Custom Runtimes
  7. Lambda Execution Environment Lifecycle
  8. Summary

Chapter 4: Cloudflare Workers Deep Dive

  1. The Cloudflare Workers Runtime Model
  2. Python on Workers: Wrapping and Bundling with esbuild
  3. Environment Variables and Secrets in Workers
  4. Durable Objects for Stateful Computations
  5. Workers KV and R2 Storage Integration
  6. Custom Domains and Routing Rules
  7. Deploying Workers with the Serverless Framework
  8. Summary

Chapter 5: API Gateway and HTTP Services

  1. AWS API Gateway Integration Patterns
  2. Cloudflare Workers Route Configuration
  3. Custom Domains and SSL/TLS
  4. Request Parsing and Response Formatting in Python
  5. CORS, Error Handling, and API Versioning
  6. Authentication Middleware Patterns
  7. Summary

Chapter 6: Event-Driven Architectures

  1. AWS Event Sources: SQS, SNS, and EventBridge
  2. DynamoDB Streams and Change Data Capture
  3. Cloudflare Queues and Scheduled Events
  4. Building a Cross-Platform Event Pipeline
  5. Dead Letter Queues and Retry Strategies
  6. Idempotency Patterns for Reliable Processing
  7. Summary

Chapter 7: Testing Serverless Python Applications

  1. Unit Testing Lambda Functions and Workers Handlers
  2. Integration Testing with LocalStack and Wrangler
  3. Mocking External Services and Dependencies
  4. Contract Testing for API Endpoints
  5. Performance and Load Testing Strategies
  6. Test Infrastructure as Code
  7. Summary

Chapter 8: CI/CD Pipelines and Multi-Stage Deployments

  1. CI/CD with GitHub Actions for Serverless
  2. GitLab CI and Alternative Pipeline Systems
  3. Multi-Stage Deployment Configuration
  4. Canary Deployments and Traffic Shifting
  5. Rollback Strategies and Disaster Recovery
  6. Pipeline Security and Secrets Management
  7. Summary

Chapter 9: Security Hardening

  1. IAM Policies and Least Privilege Enforcement
  2. Secrets Management: SSM Parameter Store, Secrets Manager, Workers Secrets
  3. Web Application Firewall (WAF) Configuration
  4. Input Validation and Output Encoding
  5. Dependency Scanning and Supply Chain Security
  6. Compliance and Audit Considerations
  7. Summary

Chapter 10: Observability, Monitoring, and Debugging

  1. Structured Logging Patterns in Python
  2. AWS CloudWatch Logs and Metrics
  3. AWS X-Ray Distributed Tracing
  4. Cloudflare Analytics and Error Tracking
  5. Custom Dashboards and Alerting
  6. Debugging Strategies: From Cold Starts to Timeouts
  7. Summary

Chapter 11: Performance Optimization and Cost Management

  1. Understanding and Mitigating Cold Starts
  2. Memory and Timeout Tuning Strategies
  3. Connection Pooling and HTTP Client Optimization
  4. Caching Patterns: Local, CDN, and Distributed
  5. Cost Monitoring and Budget Alerts
  6. Reserved Concurrency and Provisioned Capacity
  7. Summary

Chapter 12: Production Patterns and Migration Strategies

  1. Migrating Monolithic Applications to Serverless
  2. Blue-Green Deployments in Serverless
  3. Feature Flags and Gradual Rollouts
  4. Multi-Region and Edge Computing Architectures
  5. Disaster Recovery and Business Continuity
  6. The Future of Serverless Python
  7. Summary

Conclusion: Your Serverless Journey

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub