How to Create and mount AWS EFS(Elastic File System) to EC2 Instance.
Introduction to Amazon EFS
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).
In this blog, we perform some task:
Task 1: Create an Amazon EFS File System
Task 2: Mount the EFS File System on EC2 Instances
Task 3: Install Apache2 web server and host a website using aws EFS
Create an Amazon EFS File System
Step 1: Create a two EC2 instance
Step 2: Create an Amazon EFS File System
Navigate to the EFS Console:
Log in to the AWS Management Console and go to the EFS service.
Create a New File System:
- Click on “Create file system.”
3. Network Setting
4. Review and create
Step 3: 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.
Click on Create security group
Mount the EFS File System on EC2 Instances
Install NFS Utilities on both EC2 instances:
sudo apt install nfs-common
Go to your aws EFS ->> File system
click the Attach option
Copy the NFS client
Go to your EC2-Instance and mount this to your directory.
First,
mkdir
used to make a new directoryREPEAT THE SAME STEPS IN OTHER EC2-INSTANCE ALSO,
We can see that aws EFS allows multiple EC2 instances to access a shared file system
Install Apache2 web server and host a website using aws EFS
Set Up Apache Web Server in both AWS EC2 Linux (Ubuntu) Instance run below commands:
Update packages with the command ‘sudo apt-get update’.
Install Apache2 using ‘sudo apt-get install apache2’
sudo systemctl start apache2’
sudo systemctl enable apache2’
Verify that Apache is running using the command ‘sudo systemctl status apache2’
Copy the NFS client and mount to your /var/www/html directory.
-
We move index.html file into /var/www/html
Let’s also check this from web browser. Hit the public IPs of both the instances and see they are returning same data.
Conclusion
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.
Thank you for the reading!😊
Subscribe to my newsletter
Read articles from Utkarsh Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Utkarsh Gupta
Utkarsh Gupta
🚀 Hi everyone! I'm Utkarsh Gupta, IAM Consultant. I am very passionate for all things DevOps. Right now, I'm learning and working on some cool projects and I can't wait to share what I'm learning with you all! 🛠️ Here's what's in my toolbox: Linux Docker Kubernetes Jenkins AWS Python Prometheus Grafana Ansible Terraform Join me as we explore AWS DevOps together. Let's learn and grow together in this ever-changing field! 🤝 Feel free to connect with me for: Sharing experiences Friendly chats Learning together Follow my journey on Hashnode and LinkedIn for daily updates. Let's dive into the world of DevOps together! 🚀 #DevOps #AWS #DevOpsJourney #90DaysOfDevOps