Serverless Compute

AWS Lambda

AWS Lambda — Serverless Compute Service

AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume — no charge when your code is not running. It is the core service behind serverless architecture on AWS.

Overview

What is AWS Lambda?

Lambda is a compute service that runs your code in response to events and automatically manages the underlying compute resources.

Introduction

Launched in 2014, AWS Lambda pioneered the serverless computing model. You upload your code as a "Lambda function" and configure it to trigger from over 200 AWS services or HTTP requests via API Gateway. Lambda handles everything — server provisioning, auto-scaling, patching, and monitoring.

Lambda supports multiple programming languages including Node.js, Python, Java, Go, Ruby, C#, and custom runtimes. Each function runs in a stateless container with a configurable timeout (up to 15 minutes) and memory allocation (up to 10 GB).

Architecture

How Lambda Works

Event-driven execution at its core.

Execution Flow — How Lambda Works
1

Event Source

S3 upload, API call, DynamoDB stream, etc.

2

Lambda Function

Your code runs in a managed container

3

Execute Code

AWS runs your function logic

4

Store / Respond

Result saved to S3, DB, or sent back

Hot vs Cold Starts: Lambda keeps your function "warm" for a few minutes after execution. Cold starts happen when a new container spins up (adds ~100–500ms latency). Use Provisioned Concurrency to eliminate cold starts for latency-sensitive apps.

Execution Model

When an event occurs (e.g., a file is uploaded to S3), Lambda spins up a container to run your function. If the function is invoked again while still warm, the same container is reused — this is called a "warm start." After periods of inactivity, the container is recycled ("cold start"), causing a slight latency increase on the next invocation.

Features

Key Features

What makes AWS Lambda powerful for modern applications.

No Server Management

Lambda runs your code on a high-availability compute infrastructure and manages all server administration.

Automatic Scaling

From zero to thousands of concurrent executions in seconds. Lambda scales automatically based on incoming requests.

Pay Per Use

Billed in millisecond increments. No cost when your function is idle — perfect for intermittent workloads.

200+ Event Sources

Trigger from S3, DynamoDB, SQS, SNS, API Gateway, CloudWatch, EventBridge, and many more.

Versions & Aliases

Manage multiple versions, use aliases for dev/staging/prod, and implement blue/green deployments.

Built-in Security

Lambda functions run in a VPC, can access secrets via Secrets Manager, and integrate with IAM roles.

Code Example

Simple Lambda Function

An example of a Lambda function in Python that resizes an image when uploaded to S3.

Python 3.12lambda_function.py
import boto3
from PIL import Image
import os

s3 = boto3.client('s3')

def lambda_handler(event, context):
    # Get bucket & key from S3 event
    bucket = event['Records'][0]['s3']['bucket']['name']
    key = event['Records'][0]['s3']['object']['key']
    
    # Download, resize, re-upload
    download_path = '/tmp/' + key
    upload_path = '/tmp/resized-' + key
    s3.download_file(bucket, key, download_path)
    
    with Image.open(download_path) as img:
        img.thumbnail((300, 300))
        img.save(upload_path)
    
    s3.upload_file(upload_path, bucket, 'thumbnails/' + key)
    return {'statusCode': 200}
Use Cases

Real-World Examples

How companies use AWS Lambda in production.

Netflix — Content Processing

Netflix uses Lambda to automate their content encoding pipeline. When a new video is uploaded, Lambda triggers encoding jobs, validates outputs, and notifies downstream systems.

Capital One — Document Processing

Capital One processes loan applications using Lambda. Function