Running Serverless: Introduction to AWS Lambda and the Serverless Application Model

ISBN: 9780993088155 (paperback), 9780993088162 (epub)

Book by Gojko Adzic

Latest update 1. July 2017

Get the book

Read a sample to get a taste of the content.


Sign up to get notified about related updates.

Source code

JavaScript source code is available from the following link:


I am still working on publishing the code for other programming languages. Please come back in a few days, or Sign up to get notified when we publish rest of the materials on this site.

About the book

This book will help you get started with AWS Lambda and the Serverless Application Model (SAM). Lambda is Amazon's engine for running event-driven functions, and SAM is an open-source toolkit that greatly simplifies configuring and deploying Lambda services. Together, they make it easy to create auto-scaling APIs and cloud services designed for serverless deployments.

Running Serverless is a technical tutorial. It will be useful for two groups of developers and architects:

  1. People who have no previous experience working with serverless applications and are interested in learning about emerging cloud architectural patterns
  2. People who already work with Lambda using other deployment frameworks and want to learn about AWS SAM, the Serverless Application Model

You'll learn how to:

The contents of this book are based on my experiences with MindMup, a collaborative mind-mapping system that was one of the early adopters of AWS Lambda. MindMup moved to a serverless model from an application hosting service throughout 2016, in order to benefit from on-demand scaling. We reduced operational costs by about two-thirds while significantly increasing application capacity, speeding up development and reducing time to market for new features. The lessons from our migration ended up in one of the first scientific papers on the topic, and I was invited to present our experiences at conferences all over the world.

This book is structured as a walk-through for building a practical application. We start from a simple static API and gradually grow it into an online image-resizing service, ready for millions of users, with all the supporting operational and infrastructural capabilities. The application closely resembles real-world systems that many of you will develop in your jobs. This will give you a good structure for your own work, and you will be able to almost copy parts to get a head start. As you discover how to create and deploy different parts of the application, you will also learn about key aspects of Lambda and related services, important tips, techniques and tools for running serverless.

Table of contents

Copyright About the author Thanks to everyone who helped Learn about updates Introduction 1 Serverless in five minutes The serverless pricing model How request pricing affects deployment architecture How request pricing affects security How request pricing affects product decisions Important AWS Lambda technical constraints When to use Lambda 2 Set up tools for local development Setting up prerequisites Installing JavaScript tools Installing the SAM command line tools Configuring access credentials Running with restricted user accounts Using a profile 3 Create a web service Infrastructure as code The Lambda programming model Deploying SAM applications Step 1: Build Step 2: Package Step 3: Deploy Inspecting a stack Inspecting a stack from the command line 4 Development and troubleshooting Retrieving execution logs Retrieving logs from the command line Searching logs Logging incoming events Simulating Lambda locally Debugging functions Validating templates Working in a team Setting up a deployment pipeline 5 Safe deployments Function configurations Versions and aliases Gradual deployments Adding deployment alerts 6 Handling HTTP requests API Gateway events Customising responses Troubleshooting Gateway integrations Processing request parameters Using global settings to configure the implicit API Creating parameterised CloudFormation stacks Defining stack parameters Referencing parameter values Custom API domain names Provide parameter values during deployment Making stack parameters more user-friendly 7 Using external storage Cloud storage options Lambda access rights Generating unique references Using AWS resources from Lambda functions Passing resource references to functions Authorising access with IAM policies Dealing with network timeouts 8 Cheaper, faster, serverless Signing requests Signed download URLs Protecting S3 files 9 Handling platform events Generating test events Working with files Working with asynchronous events Avoiding circular references Setting custom IAM policies Handling asynchronous errors with dead letters Conditional resources 10 Using application components The AWS Serverless Application Repository Lambda layers Linking functions with layers Invoking system utilities Publishing to SAR 11 Managing sessions and user workflows Moving session state out of Lambda functions Resumable sessions Minimise coordination Moving static assets out of Lambda functions Using S3 as a web server Working with cross-origin resource sharing Configuring S3 buckets for CORS Configuring API Gateway for CORS Uploading files to S3 Using custom resources to extend CloudFormation Redeploying custom resources Uploading files without the SAR component 12 Designing robust applications API endpoints with path parameters Designing with Ports and Adapters Request processor Infrastructure adapters Lambda utility methods Lambda entry code Protecting against abuse API throttling Lambda throttling Monitoring throttling 13 Deployment options Think about jobs, not functions One Lambda or many? Aggregate processing data ownership Aggregate code that needs to be consistent Divide code around security boundaries Divide code around CPU and memory needs Divide tasks around timing restrictions Sharing behaviour Bundling shared libraries Working with Lambda layers Invoking one function from another Sharing configuration Where next?