Lambda: Serverless Functions
Lambda runs your code without you ever provisioning, patching, or managing a server — you upload a function, tell AWS what should trigger it, and it runs on demand, scaling automatically from zero to thousands of concurrent executions.
A minimal function
def lambda_handler(event, context):
name = event.get("name", "world")
return {
"statusCode": 200,
"body": f"Hello, {name}!"
}
aws lambda invoke --function-name greet --payload '{"name":"Priya"}' response.json
cat response.json{"statusCode": 200, "body": "Hello, Priya!"}Every Lambda function has a handler function with this same shape: it receives an event (the input data, shaped differently depending on what triggered the function) and returns a result. You're billed only for the milliseconds your code actually runs, not for idle time.
Triggers
A Lambda function does nothing on its own — it needs a trigger. Common ones: an API Gateway endpoint turning it into a web API, an S3 event firing whenever a file is uploaded to a bucket, or a CloudWatch scheduled event running it on a cron-like timer.
When Lambda fits and when it doesn't
Lambda is a great fit for short-lived, event-driven work: processing an uploaded image, responding to an API request, running a nightly cleanup job. It's a poor fit for long-running processes (functions have a hard 15-minute maximum runtime) or workloads that need to maintain state or a persistent connection between invocations.