DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

EBS, EFS, S3 lab that shows their behaviors

  • Behavior differences
  • Performance behavior
  • Sharing capability
  • Persistence behavior
  • Failure behavior
  • Production use cases
  • Interview-ready explanations

This will be 100% hands-on.


🧠 PART 0 β€” Quick Theory (Interview Foundation)

Feature EBS EFS S3
Type Block storage Network file system Object storage
Attach to One EC2 (per AZ) Many EC2 (multi-AZ) Anywhere via API
Mount as /dev/xvdf /mnt/efs Not mounted (API/CLI)
Shared? ❌ No βœ… Yes βœ… Yes
Multi-AZ? ❌ No βœ… Yes βœ… Yes
Use Case Database, OS disk Shared web files Backups, artifacts

Now we prove all of this practically.


πŸš€ LAB ARCHITECTURE

We will create:

  • 2 EC2 instances
  • 1 EBS volume
  • 1 EFS file system
  • 1 S3 bucket

Region: us-east-2


πŸ”΅ PART 1 β€” EBS Behavior Lab

Step 1 β€” Create EC2 #1 (Ubuntu)

Install Nginx:

sudo apt update
sudo apt install nginx -y
Enter fullscreen mode Exit fullscreen mode

Step 2 β€” Create EBS Volume

EC2 β†’ Elastic Block Store β†’ Volumes β†’ Create

  • Size: 5GB
  • AZ: same as EC2
  • Type: gp3

Attach to EC2 #1


Step 3 β€” Format and Mount EBS

lsblk
Enter fullscreen mode Exit fullscreen mode

You’ll see something like:

xvdf
Enter fullscreen mode Exit fullscreen mode

Format it:

sudo mkfs -t ext4 /dev/xvdf
Enter fullscreen mode Exit fullscreen mode

Create mount directory:

sudo mkdir /mnt/ebs
sudo mount /dev/xvdf /mnt/ebs
Enter fullscreen mode Exit fullscreen mode

Step 4 β€” Write Data

echo "EBS DATA from $(hostname)" | sudo tee /mnt/ebs/test.txt
Enter fullscreen mode Exit fullscreen mode

Check:

cat /mnt/ebs/test.txt
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ EBS Behavior Test

Try attaching same EBS to EC2 #2

You CANNOT.

πŸ‘‰ Interview Question:
Why can’t EBS attach to multiple instances?

Answer:
Because EBS is block storage β€” it behaves like a physical disk.


πŸ”₯ Stop EC2

Stop instance β†’ Start again

Check:

cat /mnt/ebs/test.txt
Enter fullscreen mode Exit fullscreen mode

Data still exists.

πŸ‘‰ Behavior:
EBS persists even if instance stops.


πŸ”₯ Terminate EC2

If you enabled β€œDelete on Termination” β†’ EBS deleted
If not β†’ EBS remains

πŸ‘‰ Production:
Database volumes disable auto-delete.


🟒 PART 2 β€” EFS Behavior Lab

What is EFS?

Image

Image

Image

Image


Step 1 β€” Create EFS

Go to:

Amazon Web Services β†’ EFS β†’ Create File System

Select VPC.


Step 2 β€” Install EFS Utils on BOTH EC2s

sudo apt install amazon-efs-utils -y
Enter fullscreen mode Exit fullscreen mode

Step 3 β€” Mount EFS

sudo mkdir /mnt/efs
sudo mount -t efs fs-XXXX:/ /mnt/efs
Enter fullscreen mode Exit fullscreen mode

Do this on BOTH instances.


Step 4 β€” Test Sharing Behavior

On EC2 #1:

echo "EFS Shared Data" | sudo tee /mnt/efs/shared.txt
Enter fullscreen mode Exit fullscreen mode

On EC2 #2:

cat /mnt/efs/shared.txt
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ You see the same file.


πŸ”₯ Stop Instance #1

File still accessible from #2.


πŸ”₯ Delete EC2 #1

File still exists in EFS.


πŸ‘‰ Interview Question:
Why is EFS good for web servers?

Answer:
Because multiple EC2 instances can share the same file system.


🟑 PART 3 β€” S3 Behavior Lab

What is S3?

Image

Image

Image

Image

Amazon Web Services β†’ S3 β†’ Create Bucket


Step 1 β€” Upload File

Upload:

test.txt
Enter fullscreen mode Exit fullscreen mode

Step 2 β€” Access via CLI

On EC2:

aws s3 ls
aws s3 cp s3://your-bucket/test.txt .
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ Behavior Test

Try mounting S3 as disk

You cannot normally.

Because S3 is object storage.


πŸ”₯ Delete EC2

Your S3 object remains.


πŸ”₯ Multi-AZ test

S3 automatically replicates across AZs.

You don’t manage AZ for S3.


🎯 FULL BEHAVIOR COMPARISON TEST

Test EBS EFS S3
Share between instances ❌ βœ… βœ…
Acts like disk βœ… βœ… ❌
Access via HTTP ❌ ❌ βœ…
Multi-AZ automatic ❌ βœ… βœ…
Good for DB βœ… ❌ ❌
Good for shared app ❌ βœ… ❌
Good for backup ❌ ❌ βœ…

🧠 Real Production Use Cases

EBS

  • RDS storage
  • EC2 OS disk
  • Databases
  • Stateful Kubernetes workloads

EFS

  • Shared WordPress uploads
  • Shared Docker volumes
  • ML training shared storage

S3

  • Terraform state
  • CI/CD artifacts
  • Backups
  • Static websites

πŸŽ“ Interview Questions They Ask

  1. Why can’t EBS be attached to multiple instances?
  2. When would you use EFS over S3?
  3. Why is S3 cheaper?
  4. What happens if AZ fails?
  5. How does EFS achieve high availability?
  6. How do you secure S3?
  7. Difference between gp2 and gp3?
  8. Can you resize EBS?
  9. Can you encrypt EFS?
  10. How do you mount EFS in Auto Scaling?

πŸ’₯ Advanced Production Twist (Very Important)

For DevOps:

Terraform Remote State

We store:

  • Terraform state in S3
  • Locking in DynamoDB
  • Application shared files in EFS
  • Databases on EBS

This is real architecture.

βœ… Architecture: ALB + ASG + EFS (Shared Storage)

Internet
   ↓
ALB
   ↓
Auto Scaling Group (2+ EC2 instances)
   ↓
All instances mount same EFS
Enter fullscreen mode Exit fullscreen mode

This demonstrates:

  • High availability
  • Horizontal scaling
  • Shared file system
  • Real production pattern

Region: us-east-2


πŸ—οΈ FINAL ARCHITECTURE

Image

Image

Image

Image

Services used:

  • Amazon Web Services
  • Amazon EC2
  • Amazon EFS
  • Elastic Load Balancing

πŸš€ PART 1 β€” Create EFS (Shared Storage)

1️⃣ Go to EFS β†’ Create File System

  • Choose your VPC
  • Enable mount targets in all subnets
  • Keep default settings

After creation, copy:

fs-xxxxxxx
Enter fullscreen mode Exit fullscreen mode

πŸš€ PART 2 β€” Create Launch Template

Go to EC2 β†’ Launch Templates β†’ Create

Configuration:

  • AMI: Ubuntu
  • Instance type: t2.micro
  • Security Group:

    • SSH (22)
    • HTTP (80)
    • NFS (2049) allowed from VPC

πŸ”₯ VERY IMPORTANT β€” Add User Data

This auto-installs Nginx + mounts EFS:

#!/bin/bash
apt update -y
apt install nginx -y
apt install amazon-efs-utils -y

mkdir /mnt/efs
mount -t efs fs-XXXX:/ /mnt/efs

echo "Instance ID: $(curl -s http://169.254.169.254/latest/meta-data/instance-id)" > /mnt/efs/index.html

rm /var/www/html/index.nginx-debian.html
ln -s /mnt/efs/index.html /var/www/html/index.html

systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Replace:

fs-XXXX
Enter fullscreen mode Exit fullscreen mode

This ensures:

All instances write to SAME file.


πŸš€ PART 3 β€” Create Target Group

EC2 β†’ Target Groups β†’ Create

  • Type: Instances
  • Protocol: HTTP
  • Port: 80
  • Health check path: /

πŸš€ PART 4 β€” Create ALB

EC2 β†’ Load Balancers β†’ Create

Type: Application Load Balancer

  • Scheme: Internet-facing
  • Select at least 2 subnets
  • Attach security group (HTTP open)
  • Attach Target Group

After creation β†’ Copy ALB DNS name.


πŸš€ PART 5 β€” Create Auto Scaling Group

EC2 β†’ Auto Scaling Groups β†’ Create

  • Choose Launch Template
  • Select 2 subnets
  • Attach to existing ALB target group
  • Desired capacity: 2
  • Min: 2
  • Max: 4

πŸŽ‰ TEST

Open:

http://your-alb-dns
Enter fullscreen mode Exit fullscreen mode

Refresh multiple times.

You will see:

Same content from shared EFS.


πŸ”₯ BEHAVIOR DEMONSTRATION

1️⃣ SSH into one instance

echo "Updated at $(date)" > /mnt/efs/index.html
Enter fullscreen mode Exit fullscreen mode

Refresh ALB.

ALL instances reflect change.

That proves:

EFS is shared.


2️⃣ Terminate one instance manually

ASG automatically launches new one.

Refresh ALB β†’ still works.

Because:

  • New instance mounts same EFS
  • Same data available

3️⃣ Scale ASG to 3

Watch:

New instance comes up
Mounts EFS
Works instantly


πŸŽ“ WHAT THIS LAB PROVES (Interview)

Why not use EBS here?

Because EBS cannot be shared between instances.

Why not use S3?

Because application needs POSIX file system behavior.

Why ALB?

  • Distributes traffic
  • Health checks
  • SSL termination
  • Path routing

Why ASG?

  • Self-healing
  • Horizontal scaling

🧠 REAL PRODUCTION USE CASES

This pattern is used for:

  • WordPress
  • CMS systems
  • Shared upload directories
  • Microservices with shared config
  • ML shared models

πŸ’Ό WHAT DEVOPS TEAM DOES HERE

DevOps responsibilities:

  • Create Launch Templates
  • Write User Data scripts
  • Configure EFS permissions
  • Configure security groups
  • Configure health checks
  • Monitor scaling behavior
  • Add CloudWatch alarms
  • Secure NFS properly

Developers:

  • Only care about app code

πŸ”₯ Interview Scenario Question

Q:
Users upload images. Suddenly images disappear after scaling. Why?

Answer:
Because they used EBS instead of shared EFS.


⚑ Production-Level Improvement

Next level:

  • Add HTTPS with ACM
  • Add Auto Scaling policy (CPU-based)
  • Add CloudWatch alarms
  • Add lifecycle hook
  • Add EFS access points
  • Mount using IAM role instead of open NFS

Top comments (0)