Skip to main content

What Is AWS Lambda?

The Serverless Model

"Serverless" doesn't mean no servers exist — it means you don't manage them. AWS provisions, scales, and maintains the underlying infrastructure. You only write and deploy your function code.

This is a shift from traditional hosting:

Traditional: You → provision server → deploy app → manage uptime → pay 24/7
Serverless: You → write function → deploy → AWS handles the rest → pay per call

How Lambda Works

  1. You write a function — a piece of code with a defined entry point called a handler
  2. You attach one or more triggers — events that invoke the function
  3. When a trigger fires, AWS spins up a container, runs your handler, and shuts it down
  4. You're billed only for the execution duration, rounded to 1ms
Trigger (HTTP request) → Lambda service → Container starts → Handler runs → Response returned → Container idles/shuts down

Anatomy of a Lambda Function

Node.js Handler

export const handler = async (event, context) => {
console.log('Event:', JSON.stringify(event));

return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello from Lambda!' }),
};
};
ParameterWhat it contains
eventThe trigger data (HTTP request body, S3 object info, etc.)
contextMetadata about the invocation (function name, timeout remaining, request ID)
Return valueThe response — for API Gateway, must include statusCode and body

Python Handler

import json

def handler(event, context):
print(f"Event: {json.dumps(event)}")
return {
'statusCode': 200,
'body': json.dumps({'message': 'Hello from Lambda!'})
}

Common Triggers

TriggerUse Case
API GatewayBuild REST APIs — HTTP request invokes the function
S3Process files when uploaded to a bucket
SQSProcess messages from a queue (background jobs)
EventBridgeScheduled tasks (cron-style) or custom event bus
DynamoDB StreamsReact to database changes in real time
SNSFan-out notifications to multiple subscribers

Cold Starts

When Lambda hasn't been invoked recently, the container that runs your function needs to be initialized — this is called a cold start and adds latency (typically 100ms–1s depending on runtime and package size).

Subsequent calls to a "warm" container are fast. Strategies to reduce cold starts:

  • Keep functions small (fewer dependencies = faster init)
  • Use Provisioned Concurrency for latency-sensitive functions
  • Prefer Node.js or Python over Java (lighter runtimes)

Billing

Lambda billing has two components:

MetricFree TierAfter Free Tier
Requests1M/month$0.20 per 1M requests
Duration400,000 GB-seconds/month$0.0000166667 per GB-second

For most small to medium applications, Lambda is effectively free or costs cents per month.

Limitations

LimitValue
Max execution timeout15 minutes
Max memory10,240 MB
Max deployment package250 MB (unzipped)
Max response payload6 MB (synchronous)

Lambda is not suitable for long-running processes (use EC2 or Fargate instead) or large in-memory datasets.