AWS Lambda tutorial: How Amazon's serverless functions work

A first-hand, step-by-step look at the ease and simplicity of Amazon's "function as a service" platform

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

Why would a developer use AWS Lambda? In a word, simplicity. AWS Lambda—and other event-driven, “function-as-a-service” platforms such as Microsoft Azure Functions, Google Cloud Functions, and IBM OpenWhisk—simplify development by abstracting away everything in the stack below the code. Developers write functions that respond to certain events (a form submission, a webhook, a row added to a database, etc.), upload their code, and pay only when that code executes.

In “How serverless changes application development” I covered the nuts and bolts of how a function-as-a-service (FaaS) runtime works and how that enables a serverless software architecture. Here, I take a more hands-on approach by walking through the creation of a simple function in AWS Lambda and then explaining some common design patterns that make this technology so powerful.

AWS Lambda, the original FaaS runtime, was first announced in 2014. The most common example used to explain how the event-driven, compute-on-demand platform works remains this one, the resizing of an image uploaded to Amazon S3:

aws lambda 01 Amazon

A picture gets uploaded to an S3 bucket, triggering an event that executes a Lambda function. Prior to the event being triggered, the function sits in a file on disk; no CPU resources are used (or billed) until the work arrives. Once the trigger fires, the function is loaded into the AWS Lambda runtime and passed information about the event. In this example, the function reads the image file from S3 into memory and creates thumbnails of varying sizes, which it then writes out to a second S3 bucket.

To continue reading this article register now