AWS Compute & Storage

TL;DR

EC2 = virtual servers (pick CPU/RAM/disk, pay per second). S3 = unlimited object storage (files, backups, static sites). Lambda = run code without servers (pay per invocation). EBS = persistent block storage attached to EC2 instances.

Explain Like I'm 12

EC2 is like renting a computer — you pick how powerful it is and pay by the hour. S3 is like Google Drive but for your apps — unlimited storage for any file. Lambda is like hiring someone to do one specific task — they show up, do the job, and leave (you only pay for the time they worked). EBS is the hard drive plugged into your rented computer.

How Compute & Storage Fit Together

AWS compute and storage architecture showing EC2, Lambda, S3, and EBS relationships and data flow

EC2 — Elastic Compute Cloud

EC2 gives you virtual servers (called instances) that you can configure with any OS, CPU, memory, and storage combination. It's the most fundamental AWS compute service.

Instance Types

FamilyOptimized ForExampleUse Case
t3/t4gGeneral purpose (burstable)t3.micro (2 vCPU, 1 GB)Dev/test, small apps
m6i/m7gGeneral purpose (steady)m6i.large (2 vCPU, 8 GB)Web servers, app servers
c6i/c7gCompute-optimizedc6i.xlarge (4 vCPU, 8 GB)Batch processing, ML inference
r6i/r7gMemory-optimizedr6i.large (2 vCPU, 16 GB)Databases, in-memory caches
p4d/p5GPU (accelerated)p4d.24xlarge (8 A100 GPUs)ML training, video encoding
Tip: The naming convention is {family}{generation}{attribute}.{size}. For example, m6i.large = general purpose (m), 6th gen, Intel (i), large size. The "g" suffix means Graviton (ARM) — often 20% cheaper for the same performance.

Launching an EC2 Instance

# Launch a t3.micro instance with Amazon Linux 2023
aws ec2 run-instances \
  --image-id ami-0c02fb55956c7d316 \
  --instance-type t3.micro \
  --key-name my-key-pair \
  --security-group-ids sg-0123456789abcdef0 \
  --subnet-id subnet-0123456789abcdef0 \
  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=my-server}]'

# Check running instances
aws ec2 describe-instances \
  --filters "Name=instance-state-name,Values=running" \
  --query "Reservations[].Instances[].[InstanceId,InstanceType,PublicIpAddress]" \
  --output table

# Stop (preserves data) vs Terminate (deletes everything)
aws ec2 stop-instances --instance-ids i-0abc123def456
aws ec2 terminate-instances --instance-ids i-0abc123def456
Warning: terminate deletes the instance and its root EBS volume (by default). Use stop to pause and save money without losing data. Enable termination protection for production instances.

S3 — Simple Storage Service

S3 stores objects (files up to 5 TB each) in buckets (containers). It's designed for 99.999999999% (11 nines) durability — your data essentially never gets lost.

Storage Classes

ClassAccess PatternCostUse Case
StandardFrequent access$0.023/GB/moActive app data, websites
Intelligent-TieringChanging/unknown$0.023/GB + monitoringUnpredictable access patterns
Standard-IAInfrequent access$0.0125/GB/moBackups, disaster recovery
Glacier InstantRare, immediate$0.004/GB/moCompliance archives
Glacier Deep ArchiveRarely (12+ hr restore)$0.00099/GB/moLong-term regulatory archives
# Create a bucket
aws s3 mb s3://my-unique-bucket-name-2026

# Upload a file
aws s3 cp ./report.csv s3://my-unique-bucket-name-2026/data/

# Sync a local directory to S3
aws s3 sync ./build/ s3://my-unique-bucket-name-2026/ --delete

# List objects
aws s3 ls s3://my-unique-bucket-name-2026/data/ --recursive

# Enable versioning (protect against accidental deletes)
aws s3api put-bucket-versioning --bucket my-unique-bucket-name-2026 \
  --versioning-configuration Status=Enabled
Info: S3 bucket names must be globally unique across all AWS accounts. Use Lifecycle Rules to automatically transition objects to cheaper storage classes (e.g., move to Glacier after 90 days).

Lambda — Serverless Compute

Lambda runs your code in response to events without provisioning servers. You upload a function, define a trigger (API Gateway, S3 upload, schedule), and AWS handles everything else — scaling, patching, and availability.

Lambda vs. EC2

AspectEC2Lambda
Server mgmtYou manage OS, patches, scalingAWS manages everything
BillingPer second while runningPer invocation + duration (ms)
Max runtimeUnlimited15 minutes per invocation
ScalingAuto Scaling Groups (minutes)Instant (0 to 1000s of concurrent)
Best forLong-running, stateful workloadsShort, event-driven tasks
# Create a Lambda function (Python)
aws lambda create-function \
  --function-name processUpload \
  --runtime python3.12 \
  --handler lambda_function.lambda_handler \
  --role arn:aws:iam::123456789012:role/lambda-s3-role \
  --zip-file fileb://function.zip

# Invoke it manually
aws lambda invoke --function-name processUpload \
  --payload '{"key": "data/report.csv"}' output.json

# View logs
aws logs tail /aws/lambda/processUpload --follow
Tip: Lambda's free tier is generous — 1 million requests and 400,000 GB-seconds per month, forever (not just 12 months). For many workloads, Lambda is effectively free.

EBS — Elastic Block Store

EBS provides persistent block storage for EC2 instances — think of it as a virtual hard drive. Unlike instance store (which dies when the instance stops), EBS volumes persist independently.

Volume TypeIOPSThroughputUse Case
gp3 (General SSD)3,000 - 16,000125 - 1,000 MB/sMost workloads (default)
io2 Block ExpressUp to 256,000Up to 4,000 MB/sDatabases needing low latency
st1 (Throughput HDD)500Up to 500 MB/sBig data, log processing
sc1 (Cold HDD)250Up to 250 MB/sInfrequent access, archives
# Create a 100 GB gp3 volume
aws ec2 create-volume --volume-type gp3 --size 100 \
  --availability-zone us-east-1a

# Attach to an EC2 instance
aws ec2 attach-volume --volume-id vol-0123456789abcdef0 \
  --instance-id i-0abc123def456 --device /dev/xvdf

# Create a snapshot (backup)
aws ec2 create-snapshot --volume-id vol-0123456789abcdef0 \
  --description "Daily backup"
Warning: EBS volumes are AZ-specific — you can't attach a volume in us-east-1a to an instance in us-east-1b. Use snapshots to copy data across AZs or Regions.

Test Yourself

When would you choose Lambda over EC2?

Choose Lambda when your workload is event-driven, short-lived (<15 min), and unpredictable in volume. Examples: processing S3 uploads, API endpoints with variable traffic, scheduled cron jobs. Choose EC2 for long-running processes, stateful applications, or workloads needing specific OS configurations.

You have 10 TB of log files that you need to keep for 7 years but rarely access. Which S3 storage class should you use?

S3 Glacier Deep Archive — at $0.00099/GB/month, 10 TB costs about $10/month. Data retrieval takes 12-48 hours, but for compliance archives that's acceptable. Use Lifecycle Rules to automatically move objects there after a set period.

What's the difference between stopping and terminating an EC2 instance?

Stop shuts down the instance but preserves the root EBS volume and attached volumes. You stop paying for compute but keep paying for EBS storage. You can restart it later. Terminate permanently deletes the instance and (by default) its root EBS volume. The data is gone forever unless you took a snapshot.

Why can't you attach an EBS volume from us-east-1a to an instance in us-east-1b?

EBS volumes are physically located in a specific AZ and provide block-level storage over the local network. Attaching across AZs would require cross-datacenter network hops, adding latency that defeats the purpose of block storage. To move data across AZs, create a snapshot (stored in S3, which is multi-AZ) and restore it in the target AZ.

What makes S3 achieve "11 nines" (99.999999999%) durability?

S3 automatically replicates every object across at least 3 Availability Zones within a Region. Each AZ has independent power, cooling, and networking. The probability of losing all 3 copies simultaneously is astronomically low. This is built-in — you don't need to configure it.

Interview Questions

A startup expects traffic to spike 10x during a product launch. How would you design the compute layer?

Use an Auto Scaling Group with EC2 instances behind an Application Load Balancer. Set scaling policies based on CPU or request count. For the API layer, consider Lambda + API Gateway which scales instantly without configuration. Pre-warm resources before the launch by running load tests. Use Spot Instances for non-critical background processing to save costs.

How would you design a cost-effective storage strategy for a data lake with hot, warm, and cold data?

Use S3 Standard for hot data (last 30 days, frequently queried). Set a Lifecycle Rule to transition to S3 Standard-IA after 30 days (warm data, occasional access). After 90 days, transition to S3 Glacier Instant Retrieval. After 1 year, move to Glacier Deep Archive. Use S3 Intelligent-Tiering for data with unpredictable access patterns. Tag objects by source for cost allocation.

Explain the difference between EBS, EFS, and S3. When would you use each?

EBS = block storage attached to one EC2 instance, like a hard drive. Use for databases and OS volumes. EFS = network file system shared across multiple EC2 instances simultaneously (NFS protocol). Use for shared config files or CMS media. S3 = object storage accessed via HTTP API. Use for data lakes, backups, static websites, and anything that doesn't need a filesystem interface. EBS is fastest, EFS is shared, S3 is cheapest and most durable.