EC2
08 / 08

Storage, Monitoring & Interview Questions

EC2: Storage, Monitoring & Interview Questions

EBS (Elastic Block Store)

EBS is network-attached block storage for EC2. Persists independently of instance lifecycle (unless DeleteOnTermination is set). Tied to one AZ. Can be detached and reattached to another instance in the same AZ.

Volume Type | Max IOPS  | Max Throughput | Use Case
------------|-----------|----------------|----------------------------------
gp3         | 16,000    | 1,000 MB/s     | General purpose — default choice
gp2         | 16,000    | 250 MB/s       | Legacy, prefer gp3
io2 Block   | 256,000   | 4,000 MB/s     | Latency-critical DBs (Oracle, SQL)
st1 (HDD)   | 500       | 500 MB/s       | Big data, sequential reads
sc1 (HDD)   | 250       | 250 MB/s       | Archive, infrequent access (cheapest)
# Create and attach EBS volume
aws ec2 create-volume \
  --availability-zone eu-west-1a \
  --volume-type gp3 \
  --size 100 \
  --iops 4000 \
  --throughput 250 \
  --encrypted \
  --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=app-data}]'

aws ec2 attach-volume \
  --volume-id vol-abc123 \
  --instance-id i-abc123 \
  --device /dev/xvdf

# Mount on Linux
sudo mkfs.ext4 /dev/xvdf
sudo mkdir /data
sudo mount /dev/xvdf /data
# Add to /etc/fstab for persistence across reboots

# Create snapshot for backup
aws ec2 create-snapshot \
  --volume-id vol-abc123 \
  --description "Before migration snapshot"

# Resize volume (no downtime needed for gp3)
aws ec2 modify-volume --volume-id vol-abc123 --size 200
# Then extend filesystem: sudo resize2fs /dev/xvdf

Instance Store

  • NVMe SSD physically attached to the host — NOT network-attached like EBS

  • Extremely fast (millions of IOPS, GB/s throughput)

  • Data lost when instance stops, hibernates, or fails — ephemeral by design

  • Cannot be detached or snapshotted

  • Use for: temporary data, cache, scratch space, buffers

  • Available on: i4i, i3, d3, c5d, m5d, r5d instance types

EFS (Elastic File System)

  • Fully managed NFS shared across multiple EC2 instances and AZs

  • Scales automatically, pay per GB used (not provisioned)

  • Mount targets in each AZ — instances mount via DNS name

  • Use cases: shared config, content management, ML training data shared across nodes

  • EFS Standard vs EFS-IA (Infrequent Access): lifecycle policies move files automatically

  • Performance modes: General Purpose (default) vs Max I/O (high concurrency)

# Mount EFS
sudo apt-get install amazon-efs-utils
sudo mount -t efs -o tls fs-abc123:/ /mnt/efs

# Or via /etc/fstab
echo "fs-abc123:/ /mnt/efs efs _netdev,tls 0 0" >> /etc/fstab

CloudWatch & Systems Manager

# CloudWatch Agent for memory/disk metrics (not available by default)
# Install on Amazon Linux 2023:
sudo dnf install -y amazon-cloudwatch-agent

# Minimal config for memory and disk
cat > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json << 'EOF'
{
  "metrics": {
    "append_dimensions": {
      "InstanceId": "${aws:InstanceId}"
    },
    "metrics_collected": {
      "mem": {"measurement": ["mem_used_percent"],"metrics_collection_interval": 60},
      "disk": {"measurement": ["disk_used_percent"],"resources": ["/"],"metrics_collection_interval": 60}
    }
  }
}
EOF
sudo systemctl enable --now amazon-cloudwatch-agent

# SSM Run Command — run commands on instances without SSH
aws ssm send-command \
  --instance-ids i-abc123 i-def456 \
  --document-name AWS-RunShellScript \
  --parameters commands='["sudo systemctl restart nginx"]'

Interview Questions

  • EC2 vs Lambda vs ECS vs EKS? EC2: full control, long-running, stateful. Lambda: event-driven, short tasks, no server management. ECS/EKS: containerized services, better for microservices.

  • What happens when you stop vs terminate? Stop: instance halted, EBS preserved, Elastic IP preserved, billed for storage only. Terminate: instance deleted, EBS deleted (if DeleteOnTermination=true), data gone.

  • How to troubleshoot SSH connection refused? Check security group allows port 22; check instance is running; check key pair matches; check sshd is running (console output); verify IAM role for SSM if using Session Manager.

  • What are placement groups for? Cluster: lowest latency between instances (HPC). Spread: separate hardware to reduce correlated failures. Partition: groups on separate hardware for distributed systems.

  • How does Auto Scaling know when to scale in? Scale-in protection, cooldown periods, deregistration delay on ALB. ASG terminates instances according to termination policy (default: oldest launch config, then closest to billing hour).

  • Reserved vs Savings Plans? Reserved: specific instance family/size/region. Savings Plans: commit to $/hour compute spend, applies across instance types, Lambda, and Fargate — more flexible.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free