- 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
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
Youβll see something like:
xvdf
Format it:
sudo mkfs -t ext4 /dev/xvdf
Create mount directory:
sudo mkdir /mnt/ebs
sudo mount /dev/xvdf /mnt/ebs
Step 4 β Write Data
echo "EBS DATA from $(hostname)" | sudo tee /mnt/ebs/test.txt
Check:
cat /mnt/ebs/test.txt
π₯ 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
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?
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
Step 3 β Mount EFS
sudo mkdir /mnt/efs
sudo mount -t efs fs-XXXX:/ /mnt/efs
Do this on BOTH instances.
Step 4 β Test Sharing Behavior
On EC2 #1:
echo "EFS Shared Data" | sudo tee /mnt/efs/shared.txt
On EC2 #2:
cat /mnt/efs/shared.txt
π₯ 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?
Amazon Web Services β S3 β Create Bucket
Step 1 β Upload File
Upload:
test.txt
Step 2 β Access via CLI
On EC2:
aws s3 ls
aws s3 cp s3://your-bucket/test.txt .
π₯ 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
- Why canβt EBS be attached to multiple instances?
- When would you use EFS over S3?
- Why is S3 cheaper?
- What happens if AZ fails?
- How does EFS achieve high availability?
- How do you secure S3?
- Difference between gp2 and gp3?
- Can you resize EBS?
- Can you encrypt EFS?
- 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
This demonstrates:
- High availability
- Horizontal scaling
- Shared file system
- Real production pattern
Region: us-east-2
ποΈ FINAL ARCHITECTURE
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
π 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
Replace:
fs-XXXX
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
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
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)