What is EFS (Elastic File System) in AWS and how to use it

Amazon Elastic File System(EFS) provides an NFS file system for use with AWS Cloud services and on-premises resources which is simple, scalable, fully managed. We can mount this file system either on AWS Cloud or our on-premises servers. It is built to scale on-demand,  grows and shrinks automatically. This means it can grow and reduce its capacity as we add or delete files on it. It is an alternative to our legacy NFS Server.

Amazon EFS can be quickly and easily created from the Web Console of AWS. This service manages the infrastructure for us, which  means we can avoid the complexity of deploying, patching, and maintaining complex file system configurations.

Amazon EFS supports the Network File System version 4 (NFSv4.1 and NFSv4.0) protocol.

To learn more about EFS, visit the AWS Official Page here.

In this article, we will focus on creating a simple EFS filesystem and mount it on Ubuntu EC2 instance.

Before we proceed, I assume that you are familiar with EC2 instances and if you are not and want to learn to create an Ubuntu 18.04 EC2 Instance from the AWS Console then Click here.

Pre-requisites

  1. AWS Account (Create if you don’t have one). 
  2. Ubuntu EC2 Instance.

What will we do?

  1. Login to AWS.
  2. Create EFS
  3. Mount EFS on EC2.

Login to AWS

Click here to go to AWS Login Page.

When we hit the above link, we will see a web page as follows where we are required to login using our login details.

AWS Login

Once you successfully login in to your account, you will see the screen as follows.

AWS Management Console

Create EFS

To create your first EFS File System on AWS, search for EFS and click on the result.

Create EFS

You will see the main dashboard of EFS. Here you can read a bit about EFS.

To create EFS click on "Create file system".

Create Filesystem

On the "Configure Network Access" page, select the VPC and checkboxes for Subnets in which you want to create an EFS and click on "Next Step". You can choose whichever VPC is available in the region you are creating the EFS.

Configure Network access

Give "key:value" if you want to add tags to the EFS, you can enable "Lifecycle Policy" so that the file system uses the lower-cost Infrequent Access storage class, keep it None for now. Keep throughput and performance mode as is.

Configure system settings

Do not enable encryption and proceed with default, click on "Next Step". You can try this later if you want to.

Lifecycle policy

Keep all these options to default and click on "Next Step".

Configure client access

Review the configurations we did and click on "Create file system".

Review settings

You can see that the creation was successful and mount targets are being created. Wait till the time Mount Target state changes to Available.

Successfully created an EFS filesystem

Once, the Mount target state changes to Available, we are ready to mount them on our EC2 instance.

Meanwhile, you can have a look at mount instructions.

EFS mount instructions

Now, before we connect to the EC2 instance, we need to add the Security group of the EFS to EC2's Security Group.

Go to the instance on which you want to mount the EFS we created and open its security group.

Launch cloud instance

Edit "Inbound Rules".

Inbound rules

Here, allow the Security Group of the EFS to access NFS Port and save rules. 

Configure security group

Mount EFS on EC2

Now we are ready to mount the EFS on EC2.

Connect to the instance and update the local package repo.

sudo apt-get update

Update packages

Install nfs-common on the instance.

sudo apt install nfs-common

Install nfs package

Install binutils

sudo apt-get -y install binutils

Install binutils

Clone efs-utils

git clone https://github.com/aws/efs-utils

Change the directory

cd efs-utils/

Build the package

./build-deb.sh

Build efs package

Install efs-utils package

sudo apt-get -y install ./build/amazon-efs-utils*deb

Install efs drivers

Create a directory where you wish to mount the EFS

sudo mkdir efs

Mount using the EFS mount helper:

Now you can Mount the EFS on your local directory using 

sudo mount -t efs fs-218e3690:/ efs

Mount using the EFS mount helper

Mount Using the NFS client:

First unmount the directory mounted in the previous step.

sudo umount /home/ubuntu/efs

Mount the EFS

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-218e3690.efs.eu-west-3.amazonaws.com:/ efs

RFS mounted on Ubuntu Linux

Mount using the EFS mount helper and the TLS mount option:

First unmount the directory mounted in the previous step.

sudo umount /home/ubuntu/efs

Mount the EFS

sudo mount -t efs -o tls fs-218e3690:/ efs

Mount EFS with TLS

Conclusion

In this article, we learn to create a simple EFS file system. We tried to mount the EFS file system on Ubuntu 18.04 EC2 instance using different available options. You can customise and create the EFS as per your need you become familiar with its basics.

Share this page:

2 Comment(s)