AWS EFS (Elastic File System)
AWS EFS (Elastic File System) – Complete Practical Guide
1️⃣ What is EFS
EFS (Elastic File System) is a managed NFS storage service in AWS used to share files between multiple servers (EC2 instances).
Key Points
-
Purpose: Share data between multiple servers
-
Storage: Automatically scales up to petabytes
-
Type: Serverless storage (no storage management required)
-
Protocol:
-
NFS v4.0
-
NFS v4.1
-
-
Integrations:
-
EC2
-
ECS
-
EKS
-
Lambda
-
Fargate
-
-
Performance Modes
-
General Purpose – Low latency (default)
-
Elastic – For very high throughput workloads
-
-
Pricing
-
AWS Free Tier gives 5 GB free
-
2️⃣ Architecture of this Practical
We will create:
EC2 Server 1 (AZ-1) ----\
---> EFS (Shared Storage)
EC2 Server 2 (AZ-2) ----/
Both servers will access same files.
3️⃣ Step 1 – Create Security Group
Go to:
AWS Console
→ EC2
→ Security Groups
→ Create Security Group
Name
efs-sg
Inbound Rules
| Type | Port | Purpose |
|---|---|---|
| SSH | 22 | Access server |
| HTTP | 80 | Web server |
| NFS | 2049 | EFS communication |
Example
SSH TCP 22 Anywhere
HTTP TCP 80 Anywhere
NFS TCP 2049 Anywhere
⚠️ Important
If NFS (2049) is not allowed
EFS cannot communicate with EC2
4️⃣ Step 2 – Create EFS
Go to:
AWS Console
→ EFS
→ Create File System
Select
Customize
Configure
Name : one
Region : ap-south-1
Type : Regional
Performance Mode : Elastic
Networking
Select VPC
Attach Security Group
efs-sg
Make sure NFS is enabled
Click
Next
→ Create File System
Now EFS is created.
5️⃣ Step 3 – Create EC2 Servers
Create 2 servers.
Server 1
Name : server1
AZ : ap-south-1a
AMI : Ubuntu
Instance : t2.micro
Security Group : efs-sg
Server 2
Name : server2
AZ : ap-south-1b
AMI : Ubuntu
Instance : t2.micro
Security Group : efs-sg
Launch both servers.
6️⃣ Step 4 – Connect to Server
SSH into server.
Example:
ssh -i key.pem ubuntu@public-ip
7️⃣ Step 5 – Install Required Packages
Run in both servers
sudo -i
Explanation
sudo -i
Switch to root user
apt update
Explanation
Updates package repository list
apt install nginx nfs-common -y
Explanation
nginx → Web server
nfs-common → Allows Linux server to mount NFS storage (EFS)
-y → Automatically confirm installation
8️⃣ Check Web Directory
ls /var/www/html/
Explanation
This is the default nginx website folder
Example output
index.nginx-debian.html
9️⃣ Step 6 – Mount EFS
Go to
EFS Console
→ Select your EFS
→ Attach
You will see mount command.
Example command:
sudo mount -t nfs4 -o \
nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport \
fs-028e9171f773dcc7f.efs.ap-south-1.amazonaws.com:/ /var/www/html/
Explanation
mount → attach storage
-t nfs4 → mount using NFS v4
nfsvers=4.1 → NFS version
rsize / wsize → read/write buffer size
hard → retry if connection fails
timeo → timeout
retrans → retry attempts
noresvport → use random ports
Mount location:
/var/www/html
So the website folder now uses EFS storage.
Run this command on both servers.
🔟 Verify Mount
df -h
Example output
Filesystem Size Used Avail Mounted on
fs-028e9171f773dcc7f.efs 8.0E 0 8.0E /var/www/html
Explanation
df -h → shows mounted storage
11️⃣ Test Shared Storage
On Server 1
cd /var/www/html
Go to website folder
Create file
touch file1
Check
ls
Output
file1
Now go to Server 2
cd /var/www/html
ls
Output
file1
✅ File is visible.
This proves EFS is shared between servers.
12️⃣ Deploy Website Code
Go to website folder.
cd /var/www/html
Clone code
git clone https://github.com/Ironhack-Archive/online-clone-amazon.git
Explanation
Downloads website source code
Move files
mv online-clone-amazon/* .
Explanation
Moves all files into current directory
Restart nginx
systemctl restart nginx
Now open browser
http://EC2-PUBLIC-IP
Website will load.
Since EFS is shared, both servers show same website.
13️⃣ Important Note (ASG)
⚠️ EFS cannot be directly attached to ASG instances automatically unless mount is configured.
Standard method:
Create EC2
→ Configure EFS
→ Create AMI
→ Use AMI in Auto Scaling Group
OR
Use User Data script to mount EFS automatically.
14️⃣ Final Architecture
+-------------+
| EFS |
| Shared NFS |
+------+------+
|
----------------------------
| |
+---------------+ +---------------+
| EC2 Server1 | | EC2 Server2 |
| AZ-1 | | AZ-2 |
| Nginx | | Nginx |
+---------------+ +---------------+
Both servers read/write same storage.
15️⃣ Important Interview Points
Why EFS?
Shared storage for multiple servers
Protocol used?
NFS v4
Port used?
2049
Max Storage?
Petabytes
Difference
| Feature | EBS | EFS |
|---|---|---|
| Type | Block | File |
| Attach | Single EC2 | Multiple EC2 |
| Protocol | None | NFS |
✅ This is a complete DevOps EFS practical.
Comments
Post a Comment