English English French French Spanish Spanish German German
Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
Share on:

How to Implement AWS EFS to Share File System between EC2?

aws security scanner
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

If you are working on a multi-server application environment where you have a requirement to share a file system between multiple servers, then you got to set up NFS (Network File System).

NFS lets you share the file system on more than one server, but implementation requires some administration skills.

In a traditional infrastructure environment, you may have to involve multiple teams, and it would take time to create NFS. But if you are using AWS, you can get it done in a few minutes with their EFS (Elastic File System) service.

YouTube video

AWS EFS lets you create scalable file storage to be used on EC2. You don’t have to bother about capacity forecasting as it can scale up or down on-demand.

A quick illustration was taken from the AWS page to give you an idea of how it works.

aws-efs-1

Some of the EFS advantages are:

  • Fully managed by AWS.
  • Low cost, pay for what you use.
  • High available & durable
  • Automatically scale up or down.
  • Scalable performance

I’ve two EC2 Ubuntu instances running, and in this tutorial, I’ll create one EFS and then mount it on both EC2 servers.

Let’s get it started.

  • Login to the AWS console
  • Go to Services and select EFS under storage (direct link)
  • Click “Create file system.”
efs-splash
  • AWS will automatically assign an IP address in the availability zone. You can do it on the next screen if you need to change it.
aws-efs-configuration-e1502700135557
  • Add the tag if you need to and select the performance mode between General purpose or Max I/O
aws-efs-type
  • Review the configuration, and if all is okay, then click “Create File System.”

It may take a few seconds, and once done, you will get a success message.

 Success!

You have created a file system. You can mount your file system from an EC2 instance with an NFSv4.1 client installed. You can also mount your file system from an on-premises server over an AWS Direct Connect connection.

You will be able to see the newly created elastic file system on the list.

efs-list

This concludes you’ve created EFS and are ready to be mounted on EC2 instances.

Mounting EFS on EC2

Before mounting, you need to install the NFS client. If you expand the list and click on “Amazon EC2 mount instructions”, you will get the details.

aws-efs-details

But let’s see how it goes.

  • Login to both EC2 instances and install the NFS client. I have Ubuntu, so I will use the following.
apt-get install nfs-common
  • Let’s create a folder where you want to mount the EFS.

Ex: /apps

cd / 
mkdir apps

Mount the file system with the command given in the instructions.

Ex:

mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-4fd14a06.efs.us-east-1.amazonaws.com:/ apps

Note: If you are encountering any issues during mount, then refer to this troubleshooting guide, and don’t forget to check the security groups to ensure the following.

  • NFS port (2049) is allowed in EC2 instance inbound rules
  • EC2 security groups are allowed in EFS security groups

It will take a few seconds, and you will notice /apps is mounted if you do df -h command

root@ip-172-31-6-238:/# df -h | grep apps 
fs-4fd14a06.efs.us-east-1.amazonaws.com:/  8.0E     0  8.0E   0% /apps 
root@ip-172-31-6-238:/#

Now, you got to log in to another server where you want to have /apps available and repeat creating a folder and mounting the EFS.

To verify, I mounted my EFS on another server and can see /apps are accessible on both servers.

root@ip-172-31-12-97:/apps# df -h | grep apps 
fs-4fd14a06.efs.us-east-1.amazonaws.com:/  8.0E     0  8.0E   0% 
/apps root@ip-172-31-12-97:/apps#

This is easy, isn’t it?

I tried creating a few files, and overall, the performance looks good. AWS EFS looks promising, and if you need file system sharing across EC2 instances, give it a try, and I am sure you will like it.

Are you interested in learning more about AWS? Check out this Udemy course.

Thanks to our Sponsors
More great readings on Cloud Computing
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Semrush is an all-in-one digital marketing solution with more than 50 tools in SEO, social media, and content marketing.
    Try Semrush
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder