TExcelTAD
Home › AWS Cloud › Amazon EFS

Amazon EFS

Amazon Elastic File System (EFS) is a managed shared file system (NFS v4) that many EC2 instances, containers and Lambda functions can mount at the same time, across all Availability Zones in a Region. It grows and shrinks automatically: you never provision a size, you pay for the data stored.

EBS vs EFS vs S3

EBS EFS S3
Type Block storage (a disk) File storage (a shared folder) Object storage (key → object)
Access One instance at a time (mostly) Thousands of clients in parallel Any client over HTTPS
Scope One AZ A Region (Multi-AZ) A Region
Size Provisioned in GB Elastic, pay per GB stored Elastic, pay per GB stored
Protocol Attached device NFS (Linux) HTTP API
Typical use Boot disks, databases Shared web content, home directories, CMS uploads Backups, data lakes, static files

For Windows file shares (SMB) or high-performance computing, look at Amazon FSx (FSx for Windows File Server, FSx for Lustre, FSx for NetApp ONTAP, FSx for OpenZFS).

Creating and mounting

bash
aws efs create-file-system --performance-mode generalPurpose \
    --throughput-mode elastic --encrypted --tags Key=Name,Value=shared-uploads
aws efs create-mount-target --file-system-id fs-0123456789abcdef0 \
    --subnet-id subnet-0aa11bb22cc33dd44 --security-groups sg-0nfs1234567890abc
# on each instance (amazon-efs-utils installed):
sudo mount -t efs -o tls fs-0123456789abcdef0:/ /mnt/uploads
df -h /mnt/uploads

Sample output of df:

text
Filesystem      Size  Used Avail Use% Mounted on
127.0.0.1:/     8.0E  1.2G  8.0E   1% /mnt/uploads

The 8.0 exabyte "size" is EFS saying "practically unlimited". You need one mount target per AZ, and its security group must allow NFS (TCP 2049) from the clients.

Model: why a shared file system?

Two web servers behind a load balancer each save user uploads. With local disks, a file uploaded through one server is missing on the other:

python · try it yourself
class Server:
    def __init__(self, name, disk):
        self.name, self.disk = name, disk
    def upload(self, path, data):
        self.disk[path] = data
    def download(self, path):
        return self.disk.get(path, "404 Not Found")

def demo(label, disk_a, disk_b):
    a, b = Server("web-a", disk_a), Server("web-b", disk_b)
    a.upload("/uploads/avatar-42.png", "<png bytes>")
    print(f"{label}: web-a -> {a.download('/uploads/avatar-42.png')}, "
          f"web-b -> {b.download('/uploads/avatar-42.png')}")

demo("local EBS disks", {}, {})
shared = {}
demo("shared EFS     ", shared, shared)
local EBS disks: web-a -> <png bytes>, web-b -> 404 Not Found
shared EFS     : web-a -> <png bytes>, web-b -> <png bytes>

(The other common fix is storing uploads in S3 instead of a file system at all, which is often the better design for new applications.)

Storage classes and lifecycle

EFS has storage classes much like S3: Standard, Infrequent Access (IA) and Archive. A lifecycle policy moves files that haven't been read for N days to a cheaper class and (optionally) back on first access. Using example prices (check the AWS pricing pages):

python · try it yourself
PRICE = {"Standard": 0.30, "IA": 0.016, "Archive": 0.008}   # example $/GB-month
READ_FEE = {"Standard": 0.0, "IA": 0.01, "Archive": 0.03}   # example $/GB read

files_gb = {"hot (read daily)": 50, "warm (read monthly)": 200, "cold (never read)": 750}
monthly_read_gb = {"hot (read daily)": 1500, "warm (read monthly)": 200, "cold (never read)": 0}

all_standard = sum(gb * PRICE["Standard"] for gb in files_gb.values())
placement = {"hot (read daily)": "Standard", "warm (read monthly)": "IA", "cold (never read)": "Archive"}
tiered = sum(files_gb[f] * PRICE[c] + monthly_read_gb[f] * READ_FEE[c] for f, c in placement.items())

print(f"1,000 GB all in Standard  : ${all_standard:7.2f}/month")
print(f"with lifecycle tiering    : ${tiered:7.2f}/month")
for f, c in placement.items():
    print(f"  {f:<20} -> {c}")
1,000 GB all in Standard  : $ 300.00/month
with lifecycle tiering    : $  26.20/month
  hot (read daily)     -> Standard
  warm (read monthly)  -> IA
  cold (never read)    -> Archive

Performance and throughput modes

  • Performance mode: General Purpose (lowest latency, the default) or Max I/O (legacy, for very parallel workloads).
  • Throughput mode: Elastic (scales automatically, pay for what you use, recommended), Provisioned (fixed MB/s) or Bursting (throughput grows with size).

Test yourself

Which storage lets 20 EC2 instances in three AZs read and write the same files at once?

  1. Amazon EBS
  2. Amazon EFS
  3. Instance store
  4. AWS Snowball

Which port must the mount target's security group allow?

  1. 22 (SSH)
  2. 443 (HTTPS)
  3. 2049 (NFS)
  4. 3306 (MySQL)

You need a shared Windows (SMB) file system. Which service fits best?

  1. Amazon EFS
  2. Amazon FSx for Windows File Server
  3. Amazon S3 Glacier
  4. Amazon EBS gp3