What is AWS Lambda, and what are its core building blocks (function, trigger, execution role)?
AWS Lambda is a Function-as-a-Service platform that runs your code in response to events without you managing any servers, built around three core pieces — the function code itself, the trigger that invokes it, and an IAM execution role that grants it permissions — like a vending machine that dispenses a specific snack (function) the moment a coin is inserted (trigger), using a pre-approved list of what it's allowed to sell (permissions).
AWS Lambda lets you upload code (as a ZIP package or a container image up to 10GB) in a supported runtime (Python, Node.js, Java, .NET, Go, Ruby, or a custom runtime) and have AWS run it automatically whenever a configured event occurs, without you provisioning or managing any servers.
The three core building blocks are:
-
The function — your actual code plus a handler entry point that AWS invokes with an event payload and a context object (containing metadata like the remaining execution time and request ID).
-
A trigger (event source) — the thing that invokes the function: an API Gateway request, an S3 object upload, a DynamoDB stream update, an SQS message, an EventBridge scheduled rule or event pattern, and dozens of other AWS services can all act as triggers.
-
An IAM execution role — a role that Lambda assumes on your function's behalf, defining exactly what other AWS resources and actions the function is allowed to perform (e.g., read from a specific S3 bucket, write to a specific DynamoDB table). This is separate from any permissions used to invoke the function itself, which are governed by resource-based policies on the function.
Lambda functions are inherently stateless between separate execution environments — you can't rely on in-memory data persisting across invocations, though AWS does opportunistically reuse a 'warm' execution environment for consecutive invocations, which is why connections initialized outside the handler (like a database client) can sometimes be reused, but should never be assumed to be guaranteed.
Current hard limits worth knowing: functions can run up to 15 minutes per invocation, use between 128 MB and 10,240 MB of memory (with CPU scaling proportionally, reaching a full vCPU at 1,769 MB), and the default account-wide concurrency limit is 1,000 concurrent executions per Region (a soft limit, raisable via a quota increase request).
Clarify the distinction between the execution role (what the function can DO to other resources) and the resource-based/invoke policy (who or what can INVOKE the function) — conflating these two is one of the most common Lambda permission mistakes among newer engineers.