How to configure EFS with an EC2 instance in AWS Cloud?

Before starting the procedure on how to configure EFS, let's have some look at what is EFS?

EFS is known as Elastic File Storage. It is a service provided by AWS which is used to store data. The most unique feature of EFS is it can be attached to multiple EC2 instances and the data of one instance gets replicated to the other instances once they are attached to the EFS.

It can store large amount of data. For standard tier, it gives 5 gb storage which is sufficient for free tier purpose. Now let's talk something about EC2:

EC2 is known as Elastic Compute Cloud. It is a service provided by AWS to launch instances/virtual machines in cloud with some templates that have the configuration in-built.

Let's see the process on how to configure EFS along with two EC2 instances:

  1. Open the AWS Management Console and search for EC2 service.
  2. Launch 2 amazon linux instances by selecting the amazon linux(free tier eligible) AMI.
  3. Once they are launched, we need to configure Apache Web Server inside the two EC2 instances. We can also store the commands in user data while creating the instances(In my case, the option was not visible, So I configured it manually). The steps are:

a. yum install httpd -y

b. cd /var/www/html

c. cat > index.html

Hello World.

d. systemctl start httpd.

systemctl enable httpd.

e. Open the web browser and copy the public IP Address of the instance and the web server is configured.

Note: In the second instance, make sure that httpd software is installed and it's started(refer a and d above).

No alt text provided for this image

The instances used in this case are Amazon Linux and Amazon Linux 3. Note down the subnet ID, security group and the availability zone of the instances.

4. Search for EFS Service in AWS management console and create a file system.

No alt text provided for this image

5. In the first instance, go to Security Tab and add a inbound rule for the security group of the instance. The inbound rule should have the protocol NFS selected so that the EFS can be mounted to that EC2 instance.(Follow the same process of point 5 for the second EC2 instance(Amazon Linux 3)).

No alt text provided for this image


6. Also make sure that the security group of the EFS is allowed for the access to EC2 instances. For this, we need to add a rule to the EFS security group as well.

7. The EFS Security group is named as 2cd7, search for this in the security groups tab(left hand navigation menu) of the EC2 service.


No alt text provided for this image


8. Now, in the EFS Service, click on the File system that is created and you will find a attach option. Click on it and copy the second command. That command is used to mount the EFS with the EC2 instances.

No alt text provided for this image

9. After copying, paste the command in the first EC2 instance(Amazon Linux) and instead of /efs, type /var/www/html(The Apache Web Server folder that we need to attach).

No alt text provided for this image
No alt text provided for this image

10. After pasting the command and making the necessary changes as above, press Enter and check using df -T command.

No alt text provided for this image


11. Once the inbound rules for the second instance(Amazon Linux 3) are added in the security group and the details checked(as mentioned in Point no 5), paste the above command for mount in the second EC2 instance and the EFS will be mounted with that instance as well.

12. Once the EFS is mounted with both the instances, we can check whether it's functioning or not by the following commands in the second EC2 instance:

a. cd /var/www/html.

b. ls

Note: You will find the index.html file which we configured in the first instance will be replicated in the second instance( As the EFS is mounted, the files in the /var/www/html folder will be stored in the EFS File System).


13. Now, copy the public IPs of both the instances and paste it in the browser.

No alt text provided for this image
No alt text provided for this image

This is how we configure EFS and attach it with the EC2 Instances.

Thank You for reading!.


To view or add a comment, sign in

More articles by Aditya Jogwar

  • Terraform Learnings

    I would like to share my further terraform learnings in this blog. If we do not want to delete all the resources which…

  • Terraform Learnings Day 2

    I would like to share some more information about terraform. HOW TO CHOOSE THE RIGHT INFRASTRUCTURE AS A CODE TOOL? The…

  • Terraform Learnings

    I would like to list my terraform day 1 learnings along with the detailed explanations of all the points. Terraform is…

  • How to host a static website on AWS S3?

    What is AWS S3? AWS Cloud has a serverless service available popularly known as S3(Simple Storage Service). It is a…

  • How to create a mail server using Lambda, API Gateway and SES service of AWS?

    Here are the steps mentioned on how to configure a mail server using AWS serverless services such as Lambda, API…

  • How to host a static website in an EC2 instance?

    We need to go through the following steps to host a static website in an EC2 instance in AWS Cloud. The steps are as…

Others also viewed

Explore content categories