DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

EFS full guide

What Is Amazon EFS?

Amazon EFS (Elastic File System) is a scalable, cloud-based file system that can be shared between multiple EC2 instances — just like a shared network drive.

It’s perfect for:

  • Web applications that need shared storage
  • CI/CD pipelines
  • Clusters or load-balanced servers

Unlike EBS, which attaches to one EC2 instance only, EFS can be accessed by many EC2s at the same time.


🚀 Step 1: Create an EFS File System

  1. In the AWS Console, search for EFS (Elastic File System).
  2. Click Create file system.
  3. Enter:
  • Name: efs-demo
  • VPC: Choose your default VPC (for example vpc-0f5cbbc2f3ce5786b)
    1. Keep the default settings (Regional, automatic mount targets).
    2. Click Create.

💡 Result:

This creates your EFS file system and 3 mount targets — one in each Availability Zone (us-east-2a, us-east-2b, us-east-2c).
These targets are how EC2 connects to your EFS.


🧩 Step 2: Configure Network Access

2.1 Find EFS Security Group

  • Go to EFS → File systems → Your EFS (fs-xxxxxxxx)
  • Click the Network tab.
  • Copy the Security Group ID (for example, sg-0fcb6a7e70b6fa5e3).

2.2 Allow EC2 to Access EFS

Now we’ll let your EC2 security group communicate with EFS.

  1. Go to VPC → Security Groups.
  2. Search for your EFS group:
   sg-0fcb6a7e70b6fa5e3
Enter fullscreen mode Exit fullscreen mode
  1. Click on it → Inbound Rules → Edit inbound rules → Add rule.

Add:

Type Protocol Port Source
NFS TCP 2049 (your EC2 security group) e.g., sg-0114625bd0ada61c9
  1. Click Save rules.

💡 Result:

This allows traffic between your EC2 and EFS over port 2049 (NFS).


💻 Step 3: Launch an EC2 Instance

  1. Go to EC2 → Launch instance.
  2. Choose:
  • Name: efs-demo
  • AMI: Ubuntu 24.04 or Amazon Linux 2
  • Instance type: t3.micro
  • Network: same VPC as EFS (vpc-0f5cbbc2f3ce5786b)
  • Subnet: same Availability Zone as your EFS mount target (e.g., us-east-2c)
  • Security group: choose the one you used in the EFS rule (sg-0114625bd0ada61c9)
    1. Click Launch instance.

🧠 Step 4: Connect to EC2 (Using the AWS Console)

  1. Go to EC2 → Instances.
  2. Select your instance (efs-demo).
  3. Click the Connect button at the top.
  4. Choose EC2 Instance Connect tab.
  5. Click Connect again.

✅ You will now see a Linux terminal in your browser:

ubuntu@ip-172-31-47-6:~$
Enter fullscreen mode Exit fullscreen mode

That’s your EC2 command line — you don’t need any SSH key or setup!


⚙️ Step 5: Check Your Availability Zone

Run:

curl http://169.254.169.254/latest/meta-data/placement/availability-zone
Enter fullscreen mode Exit fullscreen mode

✅ Expected output:

us-east-2c
Enter fullscreen mode Exit fullscreen mode

💡 This confirms which Availability Zone your EC2 is in — it must match one of your EFS mount targets.


🛠 Step 6: Install Amazon EFS Utilities

sudo apt update
sudo apt install -y git binutils make pkg-config
git clone https://github.com/aws/efs-utils
cd efs-utils
sudo ./build-deb.sh
sudo apt install -y ./build/amazon-efs-utils*deb
Enter fullscreen mode Exit fullscreen mode

✅ Purpose:
The EFS Utilities package allows you to use mount -t efs instead of manually configuring NFS.


📂 Step 7: Create a Mount Directory

sudo mkdir -p /mnt/efs/efs
Enter fullscreen mode Exit fullscreen mode

💡 This is where your EFS will appear, like a shared folder on your local drive.


🔗 Step 8: Mount the EFS

Now mount your EFS file system to the directory you created.

sudo mount -t efs -o tls fs-0ab10783d27483a12:/ /mnt/efs/efs
Enter fullscreen mode Exit fullscreen mode

✅ Explanation:

  • -t efs → tells Linux to use the EFS driver
  • -o tls → enables encryption
  • fs-0ab10783d27483a12 → your EFS ID
  • /mnt/efs/efs → the directory on your EC2

🧾 Step 9: Verify the Mount

df -hT
Enter fullscreen mode Exit fullscreen mode

✅ Example output:

Filesystem                              Type  Size  Used Avail Use% Mounted on
fs-0ab10783d27483a12.efs.us-east-2.amazonaws.com:/  efs  8.0E   0  8.0E   0%  /mnt/efs/efs
Enter fullscreen mode Exit fullscreen mode

🎯 This confirms your EFS is successfully mounted.


🧪 Step 10: Test Write Access

sudo touch /mnt/efs/efs/test.txt
ls -l /mnt/efs/efs
Enter fullscreen mode Exit fullscreen mode

✅ Example result:

-rw-r--r-- 1 root root 0 Oct 9 04:10 test.txt
Enter fullscreen mode Exit fullscreen mode

🎉 You just created a file on your EFS — if another EC2 instance mounts the same EFS, it will see the same file instantly.


🔁 Step 11: Auto-Mount on Reboot

Make EFS mount automatically every time your instance restarts.

  1. Edit /etc/fstab:
   sudo nano /etc/fstab
Enter fullscreen mode Exit fullscreen mode
  1. Add this line:
   fs-0ab10783d27483a12:/ /mnt/efs/efs efs _netdev,tls 0 0
Enter fullscreen mode Exit fullscreen mode
  1. Save (Ctrl + O, then Enter, then Ctrl + X)

  2. Test:

   sudo mount -a
   df -hT
Enter fullscreen mode Exit fullscreen mode

✅ Purpose:
Ensures your EFS mounts automatically on reboot without manual intervention.


🧭 Step 12: Confirm in the Console

EFS does not show up as “attached” under EC2 → Storage like EBS.

Instead:

  • Go to EFS → File systems → fs-0ab10783d27483a12 → Monitoring
  • Under “Client connections,” you’ll see your EC2 listed as connected.

✅ This confirms your EC2 instance is actively using the EFS.


🏁 Final Summary

Step Action Purpose
1 Create EFS Make a shared file system
2 Configure SG Allow EC2 to access via port 2049
3 Launch EC2 Create a server to use EFS
4 Connect via EC2 Instance Connect Open browser terminal
5 Check AZ Ensure same subnet as EFS target
6 Install efs-utils Add EFS mounting tools
7 Create mount directory Folder for EFS data
8 Mount EFS Attach shared file system
9 Verify Confirm it’s mounted
10 Test file Validate write access
11 Auto-mount Persist after reboot
12 Monitor Confirm connections in console

Top comments (0)