How to create Elastic File System (EFS)

  • Post category:Solutions
  • Reading time:4 mins read

With Amazon EFS (Elastic File System), applications and workloads can store files locally or in the Amazon Web Services cloud (AWS).

Features : 

  • Uses the NFSv4.1 protocol
  • Uses security group to control access to
  • Compatible with Linux based AMI
  • Encryption at rest with KMS
  • POSIX file system with file API
  • File system automatically scales, pay as usage, capacity planning

Let’s create EFS

  • In the AWS management console, type EFS and click to open

EFS

  • After clicking on Create File System, click on Customize [so we can search for additional options].

EFS

  • The name can be left blank since it is optional. Verify “Enable automatic backups” is already enabled [used to backup network processing]

EFS

  • Life cycle management is available there, and EFS frequent access storage class is available here. Keep it as default 30days (as shown in the above figure)
  • Click on next while keeping performance mode and throughput as defaults
  • We can mount it across different AZs within our VPC
  • We can use EFS across different Availability Zones because it is a network file system
  • For each AZ you have to define security group
  • Create a new Security group from EC2 console
  • Go to EC2 and from the left-hand side you will see Security Groups
  • Click on Security Groups then click on Create and give it a name as “my-efs-demo” and in description copy the same and paste it. Click on create
  • Return to EFS and deselect all security groups and select “my-efs-demo” for each Availability Zone given there and then click on Next
  • Leave the file system policies as it is and then review and create

EFS

  • After creation, you will be able to see that EFS is created

EFS

  • After the creation of EFS now we have to create 2 EC2 instances which are going to be accessing that file system. 

EFS

  • Go to EC2 console create 2 instances using Amazon AMI

EFS

  • While creating both the instances remember to select new subnet for each instance don’t keep it as default. Suppose you selected us-east-1a for the first instance so select us-east-1b for the second one

EFS

  • Click on Next and directly come to Security groups
  • Here we have to create a new Security Group so click on Create new Security Group and name it as “ec2-to-efs” and keep the description as the same
  •  Click on Next
  • Choose the existing key pair if it already there otherwise, create a new key pair and download it and click on Launch instances
  • Now quickly login to both the instances at the same time by clicking on Connect. Open a new session for the second instance

EFS

EFS

  • Now come to EFS console and select the circle and click on View Details

EFS

  • After clicking on View details, there is an Attach button, click on that and it will give you how to attach EFS to EC2 instance

EFS

  • Leave the default selection as Mount via DNS
  •  Below you will see there is a link to user guide, open that link in the new tab window
  • After opening the user guide scroll down and click on the link “Manually installing Amazon EFS client”

EFS

  • Scroll down and copy the command which starts with “sudo”

EFS

  • Copy this command and paste in both the EC2 logged instances (press enter) 
  • This will install the necessary package for EFSEFS
  • Come to EC2 instance logged in the window again and type “mkdir efs” (press enter), this will create a directory
  • Come to EC2 console and then go to Security groups
  •  In the search bar type my-efs-demo. In this Security Group, you will see that Inbound rules have not allowed anything. 
  • Click on Edit bound rules and click on Add rule. In type option search for NFS and in source option type ec2-to-efs” and select that 
  •  Click on save rules

EFS
EFS

  • Now we will run EFS mount helper command to mount efs drive 
  • Return to EFS and copy that command and paste in both the EC2 logged instances

EFS

EFS

  • Change directory by typing cd / efs in both sessions of EC2 logged instances
  • We will create a helloworld.txt file here
  • Now type “sudo touch hello-world.txt” in both the sessions (press enter)
  • To confirm type lsblk and it will show hello-world file

EFS

  • For editing type sudo vi hello-world.txt (press enter) then press “i” and then type “hello world
  • Then press Escape (ESc key) and type :wq! (press enter) and you will be out of the editor
  • To look into the content type “cat hello-world.txt“. you will see that it is mounted now
  • Please perform all the steps in both the EC2 logged instances
  • After getting the desired output terminate both the EC2 instances and Elastic File System

EFS

  • Please perform all the steps in both the EC2 logged instances
  • After getting the desired output terminate both the EC2 instances and Elastic File System

Leave a Reply