Overview and What You Will Learn
Amazon Elastic File System (EFS) is a managed, elastic NFS file system that many Linux servers and containers can mount at the same time. It grows and shrinks automatically, stores data across multiple Availability Zones, and needs no capacity planning, which makes it the standard answer when several servers must read and write the same files.
By the end of this lab you will:
- Decide between EFS, EBS, and instance store using one question: how many servers need the same files?
- Explain mount targets, Regional versus One Zone file systems, and NFS consistency
- Choose a performance mode, a throughput mode, and a lifecycle policy
- Create an encrypted file system with security groups and mount targets
- Mount it on two EC2 instances, verify sharing, and make the mount survive reboots
- Isolate applications with access points and IAM authorization
- Attach the same file system to ECS Fargate tasks
- Troubleshoot the most common mount and permission failures
Why This Matters in Production
A fleet of workers that all need the same input and output directory cannot use separate EBS volumes, because each volume is attached to one instance and invisible to the others. Typical shared-storage cases are media processing pipelines, CMS uploads, shared configuration, build caches, and machine learning datasets.
EFS lets you add a server, mount the file system, and immediately see the same files, with no sync jobs and no application changes. The trade-off is network latency on every operation, so it suits shared data, not a database's data files.
Core Principles
The right storage depends on how many servers share the data and how long it must live.
| Storage | Who can use it | Best for |
|---|---|---|
| EBS | One instance at a time (Multi-Attach only on some io1 and io2 volumes) | Boot disks, databases, single-server data |
| EFS | Thousands of Linux clients at once | Shared content, config, models, home directories |
| Instance store | One host, lost on stop or termination | Caches and scratch space |
RememberAmazon S3 is object storage accessed over an API. It is not a POSIX file system, and tools such as Mountpoint for Amazon S3 offer only limited file semantics. When applications need ordinary file operations such as appends, renames, and locks across servers, use EFS.
A Regional EFS file system has one mount target per Availability Zone. Each mount target is an IP address in your subnet. Instances reach the target in their own AZ, and all targets serve the same data.
10.0.1.50"] end subgraph B["ap-south-1b"] EC2B["EC2 instance B"] --> MTB["Mount target
10.0.2.50"] end MTA --> FS[("EFS file system
shared data")] MTB --> FS FS -.-> IA["IA and Archive
storage classes"] classDef compute fill:#326CE5,color:#ffffff classDef mount fill:#F97316,color:#ffffff classDef store fill:#10B981,color:#ffffff classDef cold fill:#475569,color:#ffffff class EC2A,EC2B compute class MTA,MTB mount class FS store class IA cold
EFS speaks NFS version 4.1 over TCP port 2049. It gives close-to-open consistency: when one client closes a file, another client that then opens it sees the new data. That is strong enough for shared directories and uploads, but two clients should not edit the same file at the same time without locking.
A Regional file system stores data redundantly across multiple AZs and survives the loss of a whole AZ. A One Zone file system keeps data in a single AZ at a lower price and suits data you can recreate.
Performance mode. Use General Purpose. It has the lowest latency per operation and is the only mode that works with Elastic throughput and One Zone. Max I/O is a legacy option with higher latency, and it cannot be combined with Elastic throughput. You cannot change the performance mode after creation.
Throughput mode. This controls bandwidth and, in practice, maximum IOPS:
| Mode | How throughput works | Use it when |
|---|---|---|
| Elastic | Scales up and down automatically, pay for data transferred | Default choice, spiky or unknown workloads |
| Provisioned | You set throughput independent of size, pay for it | Steady, known high throughput on a small data set |
| Bursting | Scales with stored size, uses burst credits | Large file systems with modest, bursty needs |
Default limits for Elastic throughput are high (hundreds of thousands of read IOPS for frequently accessed data, and a combined throughput ceiling of about 1,500 MiBps with a current amazon-efs-utils client), and they vary by Region and can be raised. Check the current EFS quotas page before sizing a very large workload.
Storage classes and lifecycle. EFS has three Regional classes, and lifecycle management moves files between them based on last access.
| Class | Meant for | Notes |
|---|---|---|
| Standard | Active data | Lowest latency, highest price per GB |
| Infrequent Access (IA) | Data read a few times a quarter | Cheaper storage, per-GB charge when read |
| Archive | Data read a few times a year or less | Cheapest storage, higher access cost |
A lifecycle policy has three settings: transition into IA after N days, transition into Archive after N days, and optionally move a file back to Standard on first access. Directory listings and other metadata operations do not count as access. Files in IA and Archive are billed at a minimum of 128 KiB each, so they are a poor fit for millions of tiny files.
Security. Four layers apply:
- Network: the mount target security group must allow inbound TCP 2049 from the client security group.
- Encryption at rest: choose it when you create the file system. You cannot turn it on later, and the console now enables it by default.
- Encryption in transit: mount with the EFS mount helper and
tls. - Identity: IAM authorization plus a file system policy, and access points that force a POSIX user and root directory per application.
When EFS is the wrong tool, use another shared store:
| Service | Protocol | Best for |
|---|---|---|
| EFS | NFS | Shared Linux files |
| FSx for Windows File Server | SMB | Windows shares and Active Directory |
| FSx for Lustre | Lustre | HPC and ML training scratch space |
FSx for NetApp ONTAP and FSx for OpenZFS cover multi-protocol and enterprise NAS needs.
Detailed Step-by-Step Practical Lab
The lab uses the AWS CLI with placeholder IDs. Replace them with your own values. All resources cost money while they exist, so complete the cleanup milestone.
Milestone 1: How to Create Security Groups for EFS
export AWS_REGION=ap-south-1VPC_ID=vpc-0a1b2c3d4e5f6a7b8APP_SG=sg-0a1b2c3d4e5f6a7b8 # security group attached to your EC2 instances EFS_SG=$(aws ec2 create-security-group \ --group-name efs-sg \ --description "NFS from application servers" \ --vpc-id "$VPC_ID" \ --query GroupId --output text) aws ec2 authorize-security-group-ingress \ --group-id "$EFS_SG" \ --protocol tcp --port 2049 \ --source-group "$APP_SG"Milestone 2: How to Create an Encrypted EFS File System
FS_ID=$(aws efs create-file-system \ --creation-token devops-shared-fs \ --performance-mode generalPurpose \ --throughput-mode elastic \ --encrypted \ --tags Key=Name,Value=devops-shared-fs \ --query FileSystemId --output text)echo "$FS_ID" # Wait until the state is "available"until [ "$(aws efs describe-file-systems --file-system-id "$FS_ID" \ --query 'FileSystems[0].LifeCycleState' --output text)" = "available" ]; do sleep 5done # Lifecycle: IA after 30 days, Archive after 90, back to Standard on first accessaws efs put-lifecycle-configuration \ --file-system-id "$FS_ID" \ --lifecycle-policies \ TransitionToIA=AFTER_30_DAYS \ TransitionToArchive=AFTER_90_DAYS \ TransitionToPrimaryStorageClass=AFTER_1_ACCESSCommon MistakeSkipping encryption at creation. EFS encryption at rest cannot be added later. You would have to create a new encrypted file system, copy the data, and switch clients, so enable it every time.
Milestone 3: How to Create Mount Targets in Each AZ
Create one mount target per AZ that has clients, using a private subnet in each.
SUBNET_A=subnet-0aaa1111bbbb2222cSUBNET_B=subnet-0ddd3333eeee4444f aws efs create-mount-target --file-system-id "$FS_ID" --subnet-id "$SUBNET_A" --security-groups "$EFS_SG"aws efs create-mount-target --file-system-id "$FS_ID" --subnet-id "$SUBNET_B" --security-groups "$EFS_SG" aws efs describe-mount-targets --file-system-id "$FS_ID" \ --query 'MountTargets[].[AvailabilityZoneName,IpAddress,LifeCycleState]' --output tableWait until both targets show available. The VPC must have DNS resolution and DNS hostnames enabled, because clients resolve FS_ID.efs.ap-south-1.amazonaws.com to the mount target in their AZ.
Milestone 4: How to Mount EFS on the First EC2 Instance
# Amazon Linux 2023sudo dnf install -y amazon-efs-utils# Amazon Linux 2 uses: sudo yum install -y amazon-efs-utils sudo mkdir -p /shared # The mount helper handles TLS and the DNS lookup of your AZ's mount targetsudo mount -t efs -o tls fs-0123456789abcdef0:/ /shared # Confirm it is an NFS mount with effectively unlimited sizedf -hT /sharedfindmnt /shared # Write a fileecho "Written by instance 1" | sudo tee /shared/test.txtcat /shared/test.txtIf you cannot install the helper, mount with plain NFS using the options AWS recommends:
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport \ fs-0123456789abcdef0.efs.ap-south-1.amazonaws.com:/ /sharedThis path does not encrypt data in transit, so prefer the helper.
Milestone 5: How to Verify Sharing from a Second Instance
# On instance 2sudo dnf install -y amazon-efs-utilssudo mkdir -p /sharedsudo mount -t efs -o tls fs-0123456789abcdef0:/ /shared cat /shared/test.txt# Written by instance 1 echo "Written by instance 2" | sudo tee /shared/test2.txt# Back on instance 1ls -l /shared# test.txt test2.txtBoth clients see the same directory. A new file is visible once the writer has closed it, which is the close-to-open consistency described earlier.
Milestone 6: How to Make the Mount Persistent Across Reboots
echo "fs-0123456789abcdef0:/ /shared efs _netdev,noresvport,tls,nofail 0 0" | sudo tee -a /etc/fstab # Test the entry without rebootingsudo umount /sharedsudo mount -afindmnt /shared_netdev waits for the network before mounting, and nofail lets the instance boot even if EFS is unreachable, so a mount problem cannot block SSH access.
Milestone 7: How to Isolate Applications with Access Points and IAM
An access point forces every connection through it to use a specific POSIX identity and root directory, so each application sees only its own folder.
AP_ID=$(aws efs create-access-point \ --file-system-id "$FS_ID" \ --posix-user Uid=1001,Gid=1001 \ --root-directory 'Path=/app-a,CreationInfo={OwnerUid=1001,OwnerGid=1001,Permissions=750}' \ --tags Key=Name,Value=app-a \ --query AccessPointId --output text) sudo mkdir -p /mnt/app-asudo mount -t efs -o tls,iam,accesspoint="$AP_ID" "$FS_ID":/ /mnt/app-aThe iam option signs requests with the instance role. The role needs elasticfilesystem:ClientMount and elasticfilesystem:ClientWrite for this file system. To enforce encryption in transit for every client, add a file system policy that denies access when aws:SecureTransport is false, using aws efs put-file-system-policy --policy file://policy.json.
Milestone 8: How to Mount EFS in ECS Fargate Tasks
Fargate has no EBS-style local persistence for shared files, but tasks on platform version 1.4.0 or later can mount EFS. This CloudFormation snippet attaches the access point from the previous milestone:
Resources: WorkerTaskDefinition: Type: AWS::ECS::TaskDefinition Properties: Family: media-worker RequiresCompatibilities: [FARGATE] NetworkMode: awsvpc Cpu: "512" Memory: "1024" TaskRoleArn: arn:aws:iam::123456789012:role/media-worker-task-role ExecutionRoleArn: arn:aws:iam::123456789012:role/ecsTaskExecutionRole Volumes: - Name: shared-data EFSVolumeConfiguration: FilesystemId: fs-0123456789abcdef0 TransitEncryption: ENABLED AuthorizationConfig: AccessPointId: fsap-0123456789abcdef0 IAM: ENABLED ContainerDefinitions: - Name: worker Image: 123456789012.dkr.ecr.ap-south-1.amazonaws.com/media-worker:1.4.2 MountPoints: - SourceVolume: shared-data ContainerPath: /dataThe task's subnets need a route to a mount target, and the EFS security group must allow the task's security group on port 2049. Hundreds of tasks can mount the same file system at once.
Milestone 9: Cleanup
# On both instancessudo umount /shared# Remove the /etc/fstab line as well aws efs delete-access-point --access-point-id "$AP_ID" for mt in $(aws efs describe-mount-targets --file-system-id "$FS_ID" --query 'MountTargets[].MountTargetId' --output text); do aws efs delete-mount-target --mount-target-id "$mt"done# Wait until describe-mount-targets returns nothing, then:aws efs delete-file-system --file-system-id "$FS_ID"aws ec2 delete-security-group --group-id "$EFS_SG"Production Best Practices & Common Pitfalls
Treat EFS as a shared network drive: great for sharing, sensitive to latency and to how clients are configured.
- Use General Purpose performance mode and Elastic throughput unless measurements show a reason to change.
- Create the file system encrypted, mount with TLS, and enforce it with a file system policy.
- Create a mount target in every AZ that runs clients so traffic stays in-AZ.
- Give each application its own access point instead of mounting the root of the file system.
- Use lifecycle policies to move cold data to IA and Archive, and enable AWS Backup for recovery and Regional replication for disaster recovery.
- Parallelise work across threads and clients, because EFS scales throughput with concurrency and a single thread sees network latency on every operation.
- Avoid using EFS for databases or for many small files that are rewritten constantly. Use EBS or a purpose-built service.
| Mistake | Problem | Fix |
|---|---|---|
| Using S3 as a shared mount | Not a POSIX file system | Use EFS for file semantics |
| No inbound 2049 rule | Mount hangs, then times out | Allow TCP 2049 from the client security group |
| Mount only on one AZ's subnet | Clients in other AZs cannot mount or pay cross-AZ traffic | One mount target per AZ |
| Unencrypted file system | Cannot be fixed in place | Recreate encrypted and copy data |
fstab entry without _netdev or nofail |
Boot can hang waiting for EFS | Add _netdev,nofail |
| Choosing Max I/O for speed | Higher latency, no Elastic throughput | Stay on General Purpose |
TipFor containers on EKS, install the EFS CSI driver and create persistent volumes backed by access points. For Lambda, attach an access point in the function configuration. The same file system can serve EC2, Fargate, EKS, and Lambda at once.
Quick Reference & Troubleshooting Commands
| Task | Command |
|---|---|
| Create file system | aws efs create-file-system --performance-mode generalPurpose --throughput-mode elastic --encrypted |
| Create mount target | aws efs create-mount-target --file-system-id FS_ID --subnet-id SUBNET --security-groups SG |
| Mount with TLS | sudo mount -t efs -o tls FS_ID:/ /shared |
| Mount via access point | sudo mount -t efs -o tls,iam,accesspoint=AP_ID FS_ID:/ /mnt/app |
| Show mount details | findmnt /shared |
| List mount targets | aws efs describe-mount-targets --file-system-id FS_ID |
| Mount helper log | sudo tail -50 /var/log/amazon/efs/mount.log |
| Unmount | sudo umount /shared |
| Symptom | First check | Likely cause |
|---|---|---|
| Mount hangs then times out | Security group rules, NACLs | Port 2049 blocked, or no mount target in that AZ |
| "Failed to resolve fs-... efs" | VPC DNS settings, Region | DNS resolution or hostnames disabled, wrong Region |
| "Access denied by server" | File system policy, IAM role | Missing ClientMount or ClientWrite, or TLS required |
| "Permission denied" on files | ls -ln on the path |
POSIX owner or mode does not match the user or access point |
| Slow with many small files | Run operations in parallel | Per-operation latency, single-threaded access |
| Stuck mount after deletion | findmnt |
Run sudo umount -l /shared and remove the fstab entry |
| Throttled I/O | CloudWatch PercentIOLimit |
At the IOPS or throughput ceiling for the mode |
RememberIf a mount fails, check the network before anything else: the mount target's security group must allow TCP 2049 from the client, and the client's subnet must be able to reach a mount target. Most EFS mount problems are one of those two.