Y NOT — Create an EFS and Access/Share Files on EFS to Multiple EC2 Instances Across Regions
EFS stands for Elastic File System. It is managed by NFS (Network File System) that can be mounted on many EC2 Instances across many Availability Zones (AZ). EBS can be attached to single EC2 Instance at a point of time whereas EFS can be mounted to multiple EC2 Instances. Hence, in case of EFS, files are shared across different EC2 Instances (provided they get mounted to same EFS).
EFS are highly available, scalable and expense (3*gp2) and they follow pay per use model (Means, EFS are billed only for the size used whereas EBS is billed based on predetermined configuration size).
- Content Management, Web Serving, Data Sharing, Word press etc.
- Uses NFS v4.1 Protocol
- Uses Security Group to control access to EFS
- EFS Compatible only with Linux based AMI and not compatible with Windows
- Encryption at rest using KMS (Key Management System)
- File System scales automatically and billing is based on pay per use model.
Let us create a new EFS now and mount them to two EC2 Instances and validate the file accessibility on both these instances.
Step 1: Create a new security group for EFS (say SG_EFS_Gateway) and one more new security group to be associated to EC2 Instances (say SG_EC2_FileSystem) . Choose EC2 Service → Network & Security → Security Groups
Associate NFS Rule where we associate Security Groups (attached to EC2 Instances) that are allowed to access EFS
Step 2 : Create an EFS File System as below
General Purpose (Default) -> for Latency sensitive use cases (eg Web server, CMS — Content management system etc)
Max I/O -> for Higher Latency, throughput, Highly parallel (eg big data, media processing etc)
Bursting → Throughput is based on disk storage
Provisioned → throughput is regardless of storage size
Standard → for frequency accessed files
Infrequently Access (EFS — IA) -> cost to retrieve files are higher, wherease lower price for storage
Step 3: Launch two EC2 Instances with security group (SG_EC2_FileSystem)
Step 4: Remotely connect to two EC2 Instances via Putty
Step 5: Go the EFS Instance and click → Attach and install the EFS mount helper package on both EC2 instances using
sudo yum install -y amazon-efs-utils
Step 6 : Create a director efs on both the instances and mount the efs drive using tls using “sudo mount -t efs -o tls fs-20ac84f1:/ efs”
Step 7: After successful mount, file created by once instance is accessible on another EC2 Instance and vice versa
Hope you enjoyed the article!