Compute Services
Understand AWS compute building blocks: EC2, Auto Scaling, Elastic Beanstalk, and Lambda, with direct Azure comparisons.
What Is It? (ELI5)
Compute is where your app code runs. EC2 is rented VM, Beanstalk is managed app hosting, Lambda runs code only when needed, and Auto Scaling adds/removes servers automatically.
Why Do We Need It?
- Different apps need different control levels.
- Scale with traffic spikes without manual effort.
- Optimize cost by paying only for required runtime.
How It Works (Technical)
| AWS Service | Purpose | Azure Equivalent |
|---|---|---|
| EC2 | Virtual machine with full OS control | Azure Virtual Machines |
| Auto Scaling | Automatic instance count changes | VM Scale Sets autoscale |
| Elastic Beanstalk | Managed app deployment platform | Azure App Service |
| Lambda | Event-driven serverless functions | Azure Functions |
Visual Representation
User Traffic -> Load Balancer -> Auto Scaling Group -> EC2 instances
Background jobs -> Lambda -> S3 / DynamoDB
Background jobs -> Lambda -> S3 / DynamoDB
Hands-on
# Launch a basic EC2 instance (example only) aws ec2 run-instances --image-id ami-xxxxxxxx --instance-type t3.micro --count 1 # Create Lambda function package workflow zip function.zip index.js aws lambda create-function --function-name demo-fn --runtime nodejs20.x --handler index.handler --zip-file fileb://function.zip --role arn:aws:iam::ACCOUNT:role/lambda-role
Debugging Scenario
Problem
EC2 launched but app is unreachable.
- Check Security Group inbound rule for app port (80/443/custom).
- Confirm instance has public IP or load balancer in front.
- Verify app process is running inside VM.
Interview Questions
Beginner: EC2 vs Lambda?
EC2 gives full server control; Lambda is serverless and event-driven.
EC2 gives full server control; Lambda is serverless and event-driven.
Intermediate: When to use Beanstalk?
When you want managed app deployment without managing every infrastructure component manually.
When you want managed app deployment without managing every infrastructure component manually.
Scenario: Traffic spikes every Friday night. What architecture fits?
Use ALB + Auto Scaling group to increase EC2 capacity automatically.
Use ALB + Auto Scaling group to increase EC2 capacity automatically.
Real-world Usage
An e-commerce app runs APIs on EC2 Auto Scaling and order processing tasks on Lambda for burst workloads.
Summary
- Use EC2 for full control, Lambda for event-driven work.
- Auto Scaling and load balancing are key for uptime.
- Beanstalk accelerates delivery for web apps.