Serverless Computing: AWS Lambda
AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers. You only pay for every 1ms your code spends executing and the number of times your code is triggered.
The “On-Demand Private Chef” Analogy
Imagine you want a gourmet meal. Instead of owning a restaurant (EC2), paying rent, electricity, and keeping staff on standby 24/7, you hire a Private Chef (Lambda) only when you are hungry. The chef arrives, cooks the specific dish you asked for, cleans up, and leaves. You don’t pay for the chef’s downtime—you only pay for the time they spent cooking your meal.
Core Concepts & The Well-Architected Framework
Operational Excellence
Lambda removes the “undifferentiated heavy lifting” of server management. AWS handles the underlying OS patching, hardware maintenance, and runtime updates, allowing teams to focus purely on code.
Performance Efficiency
Lambda scales precisely with the size of the workload. It can go from zero to thousands of concurrent executions in seconds in response to an event (like an S3 upload or an API call).
Cost Optimization
Lambda follows a 100% “Pay-as-you-go” model. If your code doesn’t run, you pay $0. Cost is calculated based on:
- Number of requests: The first 1 million requests per month are free.
- Duration: Calculated from the moment your code begins executing until it returns or terminates, rounded up to the nearest 1ms.
Service Comparison: Compute Options
| Feature | AWS Lambda | AWS Fargate | Amazon EC2 |
|---|---|---|---|
| Management | Serverless (No OS access) | Serverless Containers | Infrastructure as a Service |
| Execution Limit | 15 Minutes | No Limit | No Limit |
| Scaling | Automatic / Instant | Automatic / Fast | Manual or Auto Scaling Groups |
| Cost Model | Per Request & Duration | Per vCPU & Memory/Hour | Per Instance/Second |
Scenario-Based Learning (Decision Matrix)
IF the requirement is to process image thumbnails uploaded to S3…
THEN use Lambda (Event-driven, short execution).
IF the requirement is a long-running ETL job taking 45 minutes…
THEN use AWS Fargate or EC2 (Lambda times out at 15m).
IF the requirement is to run a legacy Windows application…
THEN use EC2 (Lambda does not support custom Windows binaries/OS access).
Exam Tips: Golden Nuggets
- The 15-Minute Rule: Lambda is not for long-running processes. If a scenario mentions a task longer than 15 minutes, eliminate Lambda.
- Memory vs CPU: You do not toggle CPU for Lambda. You allocate Memory (128MB to 10GB), and AWS allocates proportional CPU power.
- VPC Networking: By default, Lambda runs in an AWS-managed VPC with internet access. If it needs to access resources in your private VPC (like an RDS instance), you must provide VPC configuration (Subnets/Security Groups).
- Concurrency: Use Reserved Concurrency to guarantee capacity for a function; use Provisioned Concurrency to eliminate “Cold Starts” for latency-sensitive apps.
Visualizing AWS Lambda Flow
- API Gateway: REST endpoints.
- S3: File processing triggers.
- DynamoDB: Streams processing.
- EventBridge: Scheduled CRON jobs.
- Cold Starts: Latency on first hit.
- Recursive Loops: S3 -> Lambda -> S3.
- VPC DNS: Missing internet gateway.
- Hardcoded Limits: 10GB RAM max.
- Serverless API: API GW + Lambda.
- Data Transformer: Kinesis + Lambda.
- Auto-Remediation: Config + Lambda.
- File Processing: S3 + Lambda.