Javascript functions on AWS Lambda

Serverless computing allows scalability from zero to practically infinity. Inside AWS, Lambda is the key service to run functions.

But while the code is in a familiar language, the runtime environment, the connected services, and the best practices are all different than in server-based architectures.

Learn how to write Javascript functions for the AWS Lambda environment.

Want a sneak peek? Sign up for free chapters here:

It's a whole ecosystem

A Lambda function is just one piece of the serverless puzzle, as it needs other services to be useful. It can't even store its logs but sends them to a separate service inside AWS.

It gets its permissions via an IAM Role, puts its metrics and logs to CloudWatch and X-Ray, and integrates with API Gateway to provide an HTTP endpoint. S3 is the choice to store files, and for secret configuration values, you can use SSM Parameter Store.

A Lambda function integrates with these services in different ways and each of them brings complications to the mix. But a serverless success story depends on using the full ecosystem.

Lambda is a different environment than an EC2 instance

The serverless runtime environment is radically different than traditional, on-server, architectures. It brings the promise of infinite scalability, but also new problems to solve.

The problem of cold starts, the retrying model, the ephemeral local storage, and other properties of the Lambda model are all problems you need to be aware of to develop and deploy functions with success.

And it also affects how to write Javascript code to it, such as how best to initialize variables and how to use async/await.

Learn how to implement Javascript functions

This book has all the information to write Lambda functions in Javascript effectively. You'll learn:

  • How the Lambda runtime environment works
  • How to write and deploy Javascript functions
  • How to integrate the function with other services
  • Debugging Lambda
  • Add an HTTP API

...and more!


Table of contents

The Lambda execution model
 Serverless functions
 The cost model
 At-least-once execution
 Caching in /tmp
 Cold start

 Node versions
 The Lambda permission model
 How to define code
  Inline code
  File interpolation
  Adding packages with npm
 Handler argument

Programming model
 Async handler
  Async programming patterns
  Background tasks
 Input and output
  The event object
  The context object
 Environment variables
  Cause of timeouts
  Mitigating timeouts
   AWS SDK timeouts
   Promise-based timeout handling

  Custom segments

Other topics
 Storing secrets
  Using SSM
   Cache time
  OpenAPI backend
   Request parameters
   Special handlers
  Express backend

About the author
Tamás Sallai

I'm a software developer focusing mostly on cloud computing and web technologies. I'm especially interested in how to handle edge cases to end up with dependable software.

One of my main focus is security and how each part affects the whole system. I'm an AWS-certified security specialist.

Get the book

The book is available from these stores: