Here’s the complete solution addressing all three configuration areas for EFS connectivity:
1. EFS Mount Target Configuration:
You must create an EFS mount target in every Availability Zone where you have EC2 instances that need to access the file system. Mount targets are AZ-specific resources:
# Create mount targets in each AZ
aws efs create-mount-target \
--file-system-id fs-12345678 \
--subnet-id subnet-az1-private \
--security-groups sg-efs-mount-target
aws efs create-mount-target \
--file-system-id fs-12345678 \
--subnet-id subnet-az2-private \
--security-groups sg-efs-mount-target
Each mount target gets a unique DNS name, but you can use the file system DNS name (fs-12345678.efs.region.amazonaws.com) which automatically resolves to the mount target in the same AZ as the mounting instance.
2. Security Group NFS Rules:
Configure two security groups with proper NFS access:
EFS Mount Target Security Group:
{
"IpPermissions": [{
"IpProtocol": "tcp",
"FromPort": 2049,
"ToPort": 2049,
"UserIdGroupPairs": [{
"GroupId": "sg-ec2-instances",
"Description": "Allow NFS from EC2 instances"
}]
}]
}
EC2 Instance Security Group:
No specific outbound rules needed if you have default allow-all outbound. If restricted:
{
"IpPermissionsEgress": [{
"IpProtocol": "tcp",
"FromPort": 2049,
"ToPort": 2049,
"UserIdGroupPairs": [{
"GroupId": "sg-efs-mount-target"
}]
}]
}
3. VPC/Subnet Alignment:
Verify your network configuration:
# Pseudocode - Verification steps:
1. Confirm EC2 instances and mount targets in same VPC
2. Check each mount target subnet is in correct AZ
3. Verify route tables for private subnets allow local VPC traffic
4. Ensure NACLs allow TCP 2049 bidirectional (inbound AND outbound)
5. Test DNS resolution: nslookup fs-12345678.efs.us-east-1.amazonaws.com
6. Verify mount target state is "available" in all AZs
Mount Command Best Practices:
# Use recommended mount options
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-12345678.efs.us-east-1.amazonaws.com:/ /mnt/efs
Troubleshooting Steps:
- Test connectivity from EC2: `telnet fs-12345678.efs.us-east-1.amazonaws.com 2049
- Check mount target network interfaces in EC2 console (under ENIs)
- Verify DNS resolution returns IP in same subnet range as EC2 instance
- Review VPC Flow Logs for rejected connections on port 2049
- Check CloudWatch Logs for EFS mount errors if using EFS mount helper
Common Issues:
- Cross-AZ mounting without local mount target: Create mount target in every AZ
- Security group references wrong group: Use security group IDs, not names
- NACL blocking NFS: NACLs are stateless - need both inbound and outbound rules
- DNS resolution failing: Check VPC DNS settings (enableDnsHostnames and enableDnsSupport)
- Subnet route table missing local route: Should have route for VPC CIDR pointing to “local”
Best Practices:
- Create mount targets in all subnets where instances run
- Use security group references instead of CIDR blocks for dynamic security
- Enable EFS encryption at rest for sensitive data
- Implement lifecycle policies to automatically transition files to Infrequent Access storage class
- Monitor EFS performance metrics in CloudWatch (BurstCreditBalance, ClientConnections)
- Use EFS mount helper (amazon-efs-utils) for better error handling and automatic retries
- Add mount entries to /etc/fstab for automatic mounting on instance reboot
- Test failover by terminating instances in one AZ and verifying access from remaining AZs
Once you’ve created mount targets in all required AZs and configured security groups with proper NFS rules, your EC2 instances should mount the EFS file system successfully.