AWS Lambda
Lambda is a function runtime that executes code only when an event arrives instead of reserving a server ahead of time. It provides an execution layer for request-driven and event-driven compute that starts, runs the needed logic, and ends.
▶Architecture Diagram
🔗 RelationshipDashed line animations indicate the flow direction of data or requests
If image post-processing or webhook handlers run only for a few seconds, keeping a server on all day mostly means paying for idle time. Once you have to size server count ahead of every burst, even small event-driven jobs turn into operational work.
Deploying even small tasks on VMs meant paying for idle time and constantly handling patches and scaling. This led to serverless models like Lambda, where code runs only when events arrive.
Lambda deploys code as functions and spins up execution environments when events arrive from sources like API Gateway, S3, or EventBridge. After execution, there's no infrastructure to manage, and logs and metrics flow to CloudWatch.
Lambda and EC2 both run code but operate differently. Lambda executes briefly only when requests or events occur, while EC2 keeps a server running and lets you manage processes directly. If short event-driven execution and usage-based runtime are the core need, look at Lambda; if you need long-running processes and server-level control, look at EC2.
Well-suited for lightweight API backends, upload post-processing, scheduled tasks, and event-driven logic. Not a good fit when a single execution exceeds 15 minutes or you need to maintain state between invocations.