Amazon Elastic File System (EFS) is a scalable, fully-managed cloud-based file storage service provided by Amazon Web Services (AWS). It allows multiple EC2 instances to access a shared file system, which is ideal for use cases like web serving, content management, and data sharing across different applications. EFS provides the flexibility and scalability required to handle dynamic workloads and offers high availability and durability by storing data redundantly across multiple Availability Zones (AZs).
- Scalability: EFS automatically scales up or down as you add or remove files without any need for manual intervention.
- Availability and Durability: Data is stored redundantly across multiple AZs.
- Compatibility: Supports Network File System (NFS) protocol, making it compatible with various operating systems and applications.
- Security: Integrates with AWS IAM, VPC, and AWS KMS for robust security measures.
While Amazon Elastic Block Store (EBS) is a reliable storage solution, it has some limitations:
- Single Instance Attachment: EBS volumes can only be attached to a single EC2 instance at a time, limiting its use for shared storage scenarios.
- Scalability: EBS requires manual intervention to resize volumes and adjust performance, which can be cumbersome and time-consuming.
- Availability: EBS volumes are tied to a single Availability Zone (AZ), making them less resilient to AZ failures compared to EFS, which spans multiple AZs for high availability and durability.
Amazon EFS overcomes these limitations by providing a shared file system that can be accessed by multiple EC2 instances simultaneously, automatically scaling to accommodate varying workloads, and offering higher availability through multi-AZ storage.
Step 1: Create an Amazon EFS File System
- Navigate to the EFS Console:
- Log in to the AWS Management Console and go to the EFS service.
2. Create a New File System:
- Click on “Create file system.”
- Select the VPC where your EC2 instances are running.
- Choose the availability zones (AZs) and subnets where you want your EFS mount targets.
- Configure performance and throughput modes as per your requirement.
- Click on “Create” to provision your file system.
- After reviewing your settings, click on create.
Step 2: Configure Security Groups
- Edit Security Groups:
- Ensure the security groups associated with your EC2 instances allow inbound NFS traffic (port 2049).
- Also, configure the EFS security group to allow inbound NFS traffic from the security groups of your EC2 instances.
Step 3: Mount the EFS File System on EC2 Instances
- Install NFS Utilities:
- SSH into your EC2 instances, in the EC2, we have apache web server installed and we have to mount this EFS storage to our document root and for this first we need to install NFS client utilities. For Amazon Linux, use:
sudo yum install nfs-utils -y
2. Mount the EFS File System:
- Mount the EFS directory to documentRoot, i.e,
/var/www/html
: - Copy the Dns Name of your EFS storage:
- Go to your EC2-Instance and mount this to your directory.
sudo mount fs-0f125e4a9f2b41406.efs.us-west-1.amazonaws.com:/ /var/www/html/
REPEAT THE SAME STEPS IN OTHER EC2-INSTANCE ALSO, WHICH HAS THE SAME WEB SERVER SETUP:
For Web Server Setup run below 2 commands:
sudo yum install httpd -y
sudo systemctl start httpd
Step 4: Verification
- Create index.html file in one of the instance and you will see that other instance will automatically get this file.
- Now go to the second instance and check whether this file is present there or not.
- Let’s also check this from web browser. Hit the public IPs of both the instances and see they are returning same data.
- Monitoring and Logging: Use Amazon CloudWatch to monitor your EFS file system and set up alerts for critical metrics.
- Backup and Restore: Regularly back up your EFS file system using AWS Backup to protect against data loss.
- Cost Management: Be aware of the storage costs associated with EFS and use lifecycle management policies to transition infrequently accessed files to EFS Infrequent Access (IA) to reduce costs.
Amazon EFS is a powerful, scalable, and flexible file storage solution that integrates seamlessly with other AWS services. It simplifies file storage management, making it an excellent choice for applications requiring shared storage with high availability and durability. By following the practical steps outlined above, you can easily set up and use EFS in your AWS environment to enhance your application’s performance and reliability.