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.

<img alt="AWS Login" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_105739_am.png615eb5234f0c6.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="AWS Management Console" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_105834_am.png615eb5235fc8f.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Create EFS

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

<img alt="Create EFS" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_105849_am.png615eb523783a5.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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

To create EFS click on “Create file system”.

<img alt="Create Filesystem" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_105859_am.png615eb52391403.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="Configure Network access" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_105936_am.png615eb523a964f.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="Configure system settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_110046_am.png615eb523be636.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="Lifecycle policy" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_110110_am.png615eb523ce5dc.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="Configure client access" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_110147_am.png615eb523e8605.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>Advertisement

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

<img alt="Review settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_110154_am.png615eb5240fa50.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="Successfully created an EFS filesystem" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_110223_am.png615eb5242dca9.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="EFS mount instructions" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_110504_am.png615eb5244afab.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="Launch cloud instance" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_111007_am.png615eb5246bd16.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Edit “Inbound Rules”.

<img alt="Inbound rules" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_111043_am.png615eb5248ecd1.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="Configure security group" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_111111_am.png615eb524b060b.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="Update packages" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_111132_am.png615eb524d9880.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="520" loading="lazy" src="data:image/svg xml,” width=”750″>

Install nfs-common on the instance.

sudo apt install nfs-common

<img alt="Install nfs package" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_111449_am.png615eb52501ccb.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="520" loading="lazy" src="data:image/svg xml,” width=”750″>

Install binutils

sudo apt-get -y install binutils

<img alt="Install binutils" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_111807_am.png615eb52528431.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="399" loading="lazy" src="data:image/svg xml,” width=”750″>

Clone efs-utils

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

Change the directory

cd efs-utils/

Build the package

./build-deb.sh

<img alt="Build efs package" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_111839_am.png615eb5255ea88.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Install efs-utils package

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

<img alt="Install efs drivers" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_111857_am.png615eb525dc839.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="382" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="Mount using the EFS mount helper" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_112004_am.png615eb526268dc.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="247" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="RFS mounted on Ubuntu Linux" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_112057_am.png615eb5265c1f3.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="184" loading="lazy" src="data:image/svg xml,” width=”750″>

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

<img alt="Mount EFS with TLS" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/screenshot_2020-05-27_at_112157_am.png615eb5269f10c.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="253" loading="lazy" src="data:image/svg xml,” width=”750″>

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.