Mounting Elastic File System (EFS) on EC2 Linux Instance [AWS]

Mounting Elastic File System (EFS) on EC2 Linux Instance [AWS]

ยท

3 min read

Elastic File System (EFS) is one of the popular storage offerings by AWS. It is easy to use network file system which scales or shrinks automatically as files are added or removed without the need to provision and manage capacity beforehand.

Multiple compute instances like EC2(across AZs), ECS, Lambda can access EFS file system simultaneously, providing a common data socurce for applications and workloads. Plus we pay for only what we use with no minimum fee or setup cost.

In this post we will quickly see the procedure to mount EFS on Linux EC2 instances running in two availability zones.

Prerequisites:

  1. Create two Ubuntu instances in different availability zones. Ubuntu_AMI.jpg

  2. Remember the security group used for the instances created in prerequisite step 1. I have used same security group for both instances.

Secuirty_Group_EC2_Step6.jpg

Steps:

  • Create a security group for EFS using EC2 console.

    While creating the security group for EFS mention an inbound rule of type "NFS" having input as the security group created in prerequisite step number 02. This is to allow traffic from EC2 instances to EFS.

    The inbound rule will look something like the below image.

    EFS_Security_Group.jpg

  • Now create the EFS from the EFS console. Default settings can be used in first step of EFS creation.

    For second step of EFS creation specify the security group of mount targets as the EFS security group we created in Step 1.

Mount_Targets_EFS.jpg

  • Proceed to complete EFS creation
  • We will mount EFS using mount helper. For this first we need to install the amazon-efs-utils package. For this run the following commands on the ec2 instance. You can use ssh for this purpose.
sudo apt-get update
sudo apt-get -y install git binutils
git clone https://github.com/aws/efs-utils
cd /path/efs-utils
./build-deb.sh
sudo apt-get -y install ./build/amazon-efs-utils*deb
  • Once amazon-efs-utils package is installed return to home directory using cd .. Post that create a mount directory for EFS.
    sudo mkdir efs
    
  • We will mount using the file system DNS name. Mounting can also be done using file system id and mount target ip address.

    sudo mount -t efs -o tls file-system-dns-name efs-mount-point/
    

    Sample :

    sudo mount -t efs -o tls fs-abcd123456789ef0.efs.us-east-2.amazonaws.com efs/

  • You can view and copy the exact commands to mount your file system in the Attach dialog box.

(a) In the Amazon EFS console, choose the file system that you want to mount to display its details page.

(b) To display the mount commands to use for this file system, choose Attach in the upper right.

image.png

  • Repeat these steps for second EC2 instance and the EFS will be all set and accessible from the two instances in different availibilty zones.

Below I have created hello_world.txt from one ec2 instance (on the left) and same file is visible on the ec2 instance (on the right).

Final_result.jpg

Thanks for reading this blog post ๐Ÿ˜ƒ

Until next time : Happy Learning ๐Ÿ“–

Refrences:

  1. What is Amazon Elastic File System?
  2. amazon-efs-utils Tools
ย