Share File Storage with Multiple Instances simultaneously using Amazon EFS

Tejas Gupta
4 min readJun 17, 2022

--

Do you know how can we run some code which is located somewhere else on the internet and not in our system through networking?

If you think that you can run some code into your local system using google drive or Amazon s3 then you are wrong as you have to first download the code and then run it locally.

So what's the solution?

Amazon Elastic File System (EFS) is a File Storage service for the cloud. It is a highly available and durable storage service that can be connected with a lot of EC2 instances simultaneously.

A very important point to be noted about EFS is that it automatically grows and shrinks as you add and remove files with no external management and provisioning required.

Let us see how to create a File system in AWS

Step 1 — Go to the AWS console and search for EFS

Step 2 — Click on create file system

Step 3 — Enter the name of the file system and choose the VPC in which you want your file system to be present. Also, choose the availability option i.e single or multi AZs.

Step 4 — wait for some time to provision your resource and then you can attach it to your instance

Here you can have 2 scenarios

1. A new instance

while launching an EC2 instance you come across setting up the storage, so their first select EFS

Select EFS and click on Add shared file system

NOTE: If you don’t see the file system then probably you haven’t selected subnet or your instance and the EFS region doesn’t match.

Now select the file system which you created with a mount point (here we are using /var/www/html as it is the apache web server default directory)

After setting up the EFS, it will automatically add the user data to the instance for installation and mounting the storage with the folder.

Now when you launch the instance it will be automatically configured and attached to the Elastic File System

2. A running instance

For a running instance first, you need to create a folder that you want to mount with the EFS

Next, you need to install the amazon efs utils library, which will allow us to run the connection command and mount the EFS.

sudo yum install -y amazon-efs-utils

Now, As we have done with the installation, we will be creating the connection between the instance and EFS by mounting it to the folder.

Go to the File system and click on attach, you can find the command for mount using both EFS mount helper and NFS client. Use the command to create the mount.

After successfully mounting the EFS, no message will be displayed on the terminal but you can validate it with the command “mount”

see the highlighted line for the confirmation of the mount.

Now we have attached our Elastic File System to 2 different file systems but when you add a file to an instance-mounted folder then it will be available in another instance too. Now, this is something useful and can have a lot of use cases.

Thank you!

Follow Tejas Gupta for more

--

--

Tejas Gupta

AWS Community Builder ★ AWS/Azure/Alibaba Certified ★ Redhat Certified ★Cloud & DevOps Engineer ★ Content Creator