AWS Lambda runs code without managing servers—you upload a function, set a trigger, and pay per invocation and duration. Ideal for event-driven tasks and lightweight APIs.
How Lambda works
- Upload handler code (Python, Node.js, etc.)
- Configure memory (affects CPU) and timeout
- Attach IAM execution role for AWS API access
- Trigger via API Gateway, S3 events, schedules, queues
Pair with Python or Node.js tracks for handler syntax.
Cold start awareness
First invocation after idle may lag while AWS provisions runtime—keep functions small, minimize dependencies, use provisioned concurrency only when needed (cost trade-off).
List functions
aws lambda list-functions \
--query 'Functions[].{Name:FunctionName,Runtime:Runtime,Memory:MemorySize}' \
--output tablePractice: Launch resources in the EC2 Console or CLI only in a sandbox account. Use t2.micro or t3.micro where free tier applies; terminate when done.
When Lambda fits
- Image thumbnail on S3 upload
- Scheduled cleanup jobs
- Webhook processors with low steady traffic
Long-running CPU-heavy jobs often fit EC2, Batch, or containers better.
Important interview questions and answers
- Q: Lambda execution role?
A: IAM role whose temporary credentials the function uses to call AWS services. - Q: Serverless meaning?
A: You manage code and configuration; AWS manages servers, patching, and scaling.
Self-check
- What triggers a Lambda function?
- Why attach an IAM role to Lambda?
Tip: Keep Lambda handlers small; heavy dependencies increase cold start time.
Interview prep
- Serverless?
AWS manages servers; you provide code, triggers, and IAM execution role.
- Execution role?
IAM role granting Lambda permission to call other AWS services.