EFS Shared File Storage

Elastic File System is a managed, elastic file system that many EC2 instances can mount at the same time.

Amazon EFS (Elastic File System) is a fully managed NFS file system. Unlike an EBS volume, which attaches to a single instance in one AZ, EFS can be mounted by many instances across multiple AZs at once.

When to choose EFS

  • Shared content or uploads served by a fleet of web servers.
  • Home directories or shared configuration across a cluster.
  • Any workload that needs a POSIX file system with concurrent access.

How it scales

EFS grows and shrinks automatically as you add and remove files — there is no capacity to provision. You pay for the storage you use, and lifecycle management can move rarely used files to a cheaper Infrequent Access tier.

Quick comparison

EBSEFSS3
TypeBlockFile (NFS)Object
Attach to1 instanceMany instancesOver HTTP
ScopeOne AZMulti-AZRegional

Example

Example · bash
# Create an EFS file system
aws efs create-file-system --performance-mode generalPurpose \
  --tags Key=Name,Value=shared-files

# Mount it from inside a Linux EC2 instance
sudo dnf install -y amazon-efs-utils
sudo mkdir -p /mnt/efs
sudo mount -t efs fs-0123456789abcdef0:/ /mnt/efs

When to use it

  • Multiple EC2 web servers mount the same EFS file system to share user-uploaded content without synchronization logic in the application.
  • A container orchestration cluster mounts EFS as a persistent volume so containers restarting on different nodes retain their file state.
  • A development team mounts EFS on all team EC2 instances to share a common codebase directory, replacing a shared NFS server.

More examples

Create an EFS File System

Creates an EFS file system in general-purpose mode, which suits most latency-sensitive workloads.

Example · bash
aws efs create-file-system \
  --performance-mode generalPurpose \
  --throughput-mode bursting \
  --tags Key=Name,Value=shared-storage \
  --query '{FileSystemId:FileSystemId,State:LifeCycleState}' \
  --output table

Create a Mount Target in a Subnet

Creates a mount target in a subnet, giving EC2 instances in that subnet a network endpoint to mount the EFS file system.

Example · bash
aws efs create-mount-target \
  --file-system-id fs-0abc1234def56789a \
  --subnet-id subnet-0abc123 \
  --security-groups sg-0abc123

Mount EFS on EC2 Instance

Uses the amazon-efs-utils mount helper to mount EFS with encryption in transit and IAM-based access control.

Example · bash
# Install the EFS mount helper
sudo yum install -y amazon-efs-utils

# Mount using the helper (handles TLS and retries)
sudo mkdir -p /mnt/efs
sudo mount -t efs \
  -o tls,iam \
  fs-0abc1234def56789a:/ \
  /mnt/efs

Discussion

  • Be the first to comment on this lesson.