Compute Options Overview#

AWS offers compute at every abstraction level — from bare metal to fully managed serverless:

flowchart TD
    subgraph Control["More Control"]
        BM["Bare Metal<br>(EC2 .metal)"]
        EC2["EC2 Instances<br>(Virtual Machines)"]
    end
    
    subgraph Managed["Managed"]
        ECS["ECS / EKS<br>(Containers)"]
        Batch["AWS Batch<br>(Job scheduling)"]
    end
    
    subgraph Serverless["Serverless"]
        Lambda["Lambda<br>(Functions)"]
        Fargate["Fargate<br>(Serverless containers)"]
    end
    
    Control -.->|"Less ops overhead →"| Managed
    Managed -.->|"Less ops overhead →"| Serverless

EC2 (Elastic Compute Cloud)#

Virtual machines in the cloud. You choose the OS, instance type, storage, and networking.

Instance Types#

Instance types follow the pattern: {family}{generation}.{size}

FamilyOptimized ForExampleUse Case
tBurstable generalt3.microDev, low-traffic web
mGeneral purposem6i.xlargeWeb servers, app servers
cComputec6i.2xlargeBatch processing, ML inference
rMemoryr6i.4xlargeIn-memory caches, databases
iStorage I/Oi3.largeDatabases, data warehouses
g/pGPUg5.xlargeML training, video encoding

Instance Lifecycle#

stateDiagram-v2
    [*] --> Pending: Launch
    Pending --> Running: Ready
    Running --> Stopping: Stop
    Stopping --> Stopped: Stopped
    Stopped --> Pending: Start
    Running --> ShuttingDown: Terminate
    ShuttingDown --> Terminated: Done
    Stopped --> ShuttingDown: Terminate
    Terminated --> [*]

Purchasing Options#

OptionDiscountCommitmentBest For
On-Demand0%NoneUnpredictable workloads
Reserved (1yr)~40%1 yearSteady-state workloads
Reserved (3yr)~60%3 yearsLong-term stable workloads
Savings Plans~40-60%$/hr commitmentFlexible across instance types
Spot~70-90%None (can be interrupted)Fault-tolerant batch jobs

User Data (Bootstrap Script)#

#!/bin/bash
# Runs on first boot
yum update -y
yum install -y docker
systemctl start docker
systemctl enable docker
docker pull myapp:latest
docker run -d -p 80:8080 myapp:latest

Auto Scaling#

Automatically adjusts the number of EC2 instances based on demand:

flowchart LR
    ASG["Auto Scaling Group"]
    ASG --> Min["Min: 2"]
    ASG --> Desired["Desired: 3"]
    ASG --> Max["Max: 10"]
    
    CW["CloudWatch Alarm<br>CPU > 70%"] -->|"Scale Out"| ASG
    CW2["CloudWatch Alarm<br>CPU < 30%"] -->|"Scale In"| ASG

Scaling Policies#

PolicyHow It WorksUse Case
Target TrackingMaintain metric at target value“Keep CPU at 50%”
Step ScalingAdd/remove N instances per threshold“Add 2 if CPU > 80%”
ScheduledScale at specific times“Scale up at 9am weekdays”
PredictiveML-based forecastingRecurring traffic patterns

Lambda#

Run code without provisioning servers. Pay only for execution time.

How Lambda Works#

sequenceDiagram
    participant Trigger as Event Source
    participant Lambda as Lambda Service
    participant Fn as Your Function
    
    Trigger->>Lambda: Event (API Gateway, S3, SQS...)
    Lambda->>Lambda: Find/create execution environment
    Lambda->>Fn: Invoke with event payload
    Fn->>Fn: Execute handler
    Fn-->>Lambda: Return response
    Lambda-->>Trigger: Response

Lambda Characteristics#

PropertyValue
Max execution time15 minutes
Memory128 MB – 10,240 MB
Temp storage512 MB – 10 GB (/tmp)
Deployment package50 MB (zip), 250 MB (unzipped)
Concurrent executions1,000 default (adjustable)
Cold start100ms – 10s (depends on runtime, VPC)

When to Use Lambda vs Containers#

LambdaContainers (ECS/Fargate)
Event-driven, short tasksLong-running services
< 15 min executionNo time limit
Unpredictable trafficSteady traffic
Simple deploymentComplex multi-container apps
Auto-scales to zeroMinimum 1 task running

Elastic Beanstalk#

Platform-as-a-Service — deploy applications without managing infrastructure:

flowchart TD
    Code["Your Code"] --> EB["Elastic Beanstalk"]
    EB --> EC2["EC2 Instances"]
    EB --> ALB["Load Balancer"]
    EB --> ASG["Auto Scaling"]
    EB --> RDS["Database (optional)"]
    EB --> CW["CloudWatch Monitoring"]

Supports: Java, .NET, PHP, Node.js, Python, Ruby, Go, Docker.

Good for: teams that want to deploy quickly without learning all AWS services individually. You still have full access to underlying resources.


Choosing Compute#

flowchart TD
    Start["What are you running?"]
    Start --> Q1{"Long-running<br>service?"}
    Q1 -->|"Yes"| Q2{"Need full<br>OS control?"}
    Q1 -->|"No"| Q3{"Event-driven?"}
    
    Q2 -->|"Yes"| EC2["EC2"]
    Q2 -->|"No"| Q4{"Containers?"}
    
    Q4 -->|"Yes"| Fargate["ECS + Fargate"]
    Q4 -->|"No"| EB["Elastic Beanstalk"]
    
    Q3 -->|"Yes"| Lambda["Lambda"]
    Q3 -->|"No"| Q5{"Batch job?"}
    Q5 -->|"Yes"| Batch["AWS Batch"]
    Q5 -->|"No"| Lambda

Key Takeaways#

  1. EC2 for full control — you manage the OS, patching, scaling
  2. Lambda for event-driven — no servers, pay per invocation, auto-scales
  3. Fargate for containers without servers — no EC2 management, per-task billing
  4. Spot instances for cost savings — up to 90% off, but can be interrupted
  5. Auto Scaling for elasticity — match capacity to demand automatically
  6. Right-size instances — monitor CPU/memory and adjust; oversizing wastes money
  7. Use Savings Plans — commit to $/hr for predictable workloads, save 40-60%