Step-by-Step Guide: How to Create and Mount AWS EFS (Elastic File System)

Your Guide to Setting Up an Elastic File System on AWS

Step-by-Step Guide: How to Create and Mount AWS EFS (Elastic File System)

In this article, we will learn about AWS EC2 Instance Storage i.e. EFS (Elastic File System), how to create it, how to mount it to EC2 instances. In today’s modern world we need a storage solution that is scalable, efficient and flexible to scale our business to handle growing data demands.

Overview of AWS EFS (Elastic File System)

As we know AWS offers 200+ services which makes the best cloud solution which meets our business needs whether it’s in AI field, DevOps field. If we talk about EC2 i.e. Elastic Compute Cloud storage solutions it offers EBS (Elastic Block Storage) and EFS (Elastic File System).

Elastic File System is Network Shared Filesystem (NFS) that means multiple 100s of EC2’s in different AZ’s (Availability Zone’s) can talk to single central storage that is mounted where multiple EC2’s can store files on network. In simple, we have 100’s of EC2 in AZ1 and 100’s of EC2 in AZ2 they have single filesystem where they can store files and can see these files in other AZ’s also. That’s make it very highly scalable, flexible and also expensive as it is 3 times of gp2 price.

Prerequisites for Setting Up AWS EFS

  1. AWS Account

  2. EFS Client Installed

  3. IAM Permissions

Step-by-Step Guide to Creating an AWS EFS

  1. Open AWS Management Console and on top in Search Bar, write EFS.

  2. Open EFS and click on Create Filesystem. Select the default VPC and the Name is optional so keep it blank or you can provide name.

  3. Go to Customize you will see the lot of configuration options, we will go step by step understand it what it is.

    • Filesystem Type: In filesystem type there are 2 options. This is for Availability and Durability.

      • Regional: In regional, the EFS will be available in Multi-AZ which will be great for Production.

      • One-Zone: One-Zone means EFS will be available in single AZ which is great for testing purpose or dev environments that will be cost-saving.

    • Automatic Backups: It will take backup of your data automatically. For now, we will check this.

    • Lifecycle Management: EFS provides lifecycle that means it will automatically move the file to the Storage Tier after N number of days. EFS provides 3 types of storage tiers that are:

      • Standard (Default): When we are frequently accessing files it lies in Standard storage tier.

      • EFS-IA (Infrequent Access): Infrequent Access means a certain number of days passed but we do not accessing the file frequently. Like if I set 60 Days if the file is not accessed in 60 Days it will automatically move to the EFS-IA that will be cost effective and cheaper.

      • Archive: In Archive, it is more 50% cheaper, the data that we are accessing very few times in a year so it will automatically move to Archive storage tier.

        Archive Storage Tier is not available in One-Zone.

This all done by setting lifecycle management on EFS, we will leave it default.

In this, we had set the Transition to Standard to On First Access means whenever the file is accessed first time it will automatically to Standard Storage tier.

  • Performance Settings: EFS provides 2 throughput modes i.e. Enhanced and Bursting.

    • In Enhanced Throughput mode there are 2 methods:

      1. Elastic: This is the recommended one because it automatically scales the throughput UP and DOWN on workload.

      2. Provisioned: In provisioned one, we had to decide the throughput size.

    • In Bursting Mode it has the General Purpose and Max I/O performance settings. General Purpose is recommended for Web Servers and Max I/O is recommended where we need low latency like for data analytics.

      For now, we are going with default settings Elastic Throughput Mode and General Purpose Performance Setting. Click on “Next”

  1. Now, we will move to the Network Access where we choose the VPC and set the Mount Targets. As it is One-Zone so, we will set the Mount Target in single Availability Zone (AZ)

    But, before attaching this security group we will create new Security Group for EFS where we will allow ALL-TRAFFIC.

    After this, select the security group of EFS-Demo in Mount Target.

  2. Then, click on Next where the page opens Filesystem Policy leave it as it is then you will reach to Review and Create and click on Create.

  3. Now, the EFS filesystem is successfully created. Let’s move to the EC2 section where we will create 2 EC2 instances in different Availability Zone’s.

    In EFS Filesystem we only Pay what we use and one thing more only Linux distributions can be attached to EFS filesystem not Windows.

  4. Create EC2 Instance name EFS-Demo-1 in us-west-1a (N.California), then select the AMI (Amazon Machine Image)OS of Ubuntu 22.04 you can select anyone of Linux distribution, then select t2.micro Instance Type and select Proceed without KeyPair.

    Now, here comes the Network Settings Part, click on Edit and choose Subnet of us-west-1a other things leave it as default.

    Scroll Down to Configure Storage section where EBS volume have 8 Gib of gp2 and scroll down you will see you will see Filesystems click on Edit then you can see our created EFS Filesystem.

    If we don’t want to do this we had to run some commands but for now I am configuring this with EC2 configuration settings.

    Now click on Add Shared Filesystem it will automatically set the mount point and create Security Groups and attach it to EFS.

  5. Now, click on Create the Instance and with same settings click 2nd instance in another Availability zone us-west-1c and select the existing security group that is attached to Instance 1 and use the same EFS Filesystem.

    Here, now you see security group (efs-sg-1) is automatically attached to EFS Mount Targets.

    In newly created Security Group the Inbound Rules is NFS of port 2049 where the destination is Instance Security Group ID.

    Now our 2 instances are ready which are in different Availability Zone’s and we can see in mount targets Instance 2nd Security Groups is also attached.

  6. Let’s connect to Instance 1 and create file on mount target (/mnt/efs/fs1). Go to Instance 1 and click on Connect to Instance, in Ubuntu OS we need to run the commands on both the instances

    Then check the mount point exists or not if not exists create this.

    Check that the filesystem is mounted or not by executing the command.

     df -h | grep efs
    

    Create Sample hello.txt in this folder in Instance 1 and checks that the file is created in Instance 1 is we can see or not.

     echo "hello-world from Instance 1" > /mnt/efs/fs1/hello.txt
    

  7. Now connect to Instance-2 and check that the file is accessible or not.

Conclusion

In this article, we had learnt how to create EFS (Elastic File System) and mount it to EC2 instances. EFS can scale up to Petabytes automatically. Meanwhile in the upcoming blogs you will see a lot of AWS Services creation and automating it with terraform. Stay tuned for the next blog !!!

GitHub Code : github.com/amitmaurya07/AWS-Terraform/tree..

Twitter : x.com/amitmau07

LinkedIn : linkedin.com/in/amit-maurya07

If you have any queries you can drop the message on LinkedIn and Twitter.