How to create and mount EFS file system

Share

Amazon Elastic File Storage or AWS EFS is a cloud storage service that provides a simple, serverless, scalable, and encrypted file system that can be used with both AWS cloud services and on-premise resources. It is designed to grow and shrink automatically as you add and remove files, removing the need to provide and manage capacity to meet expansion. It can scale on demand to petabytes without interfering with applications.

An Amazon Elastic File System file system can be accessed by several compute instances simultaneously, including Amazon EC2, Amazon ECS, and AWS Lambda, providing a shared data source for workloads and applications running on multiple compute instances or servers.

In this blog, we will create an EFS filesystem and mount it to an EC2 instance.

Step1: Create an EFS filesystem

  • First, we will create a security group for EFS. Go to EC2 dashboard->Security Groups. Select Create security group.
  • Give a name and select VPC. We will be using default VPC.

 

  • Scroll down and click Create Security Group.
  • Now go to Elastic File System Console and click Create file system and select Customize.
  • Give a name and select storage class.
  • The Standard storage and Standard Infrequent Access storage stores data in multiple availability zones offering a high level of durability and availability whereas the One Zone Storage and One Zone Infrequent Access storage class stores data in a single availability zone offering additional cost savings.
  • We will be selecting the Standard storage class.

  • Select lifecycle rule for transitioning data to Standard-IA storage class.

  • Next select Performance mode. The default General Purpose performance mode offers low latency whereas Max I/O mode offers higher throughput and operations per second but with higher latency for file system operations.
  • We will be selecting the default General Purpose performance mode.

  • Next, select the Throughput mode. Throughput scales as your file system grows when using default Bursting Throughput mode whereas you can specify the throughput of your file system irrespective of the data stored when using Provisioned Throughput Mode.
  • We will be selecting the default Bursting mode.
  • Enable encryption of data at rest.

  • Add tags and click Next.
  • Select VPC. We will be using the default VPC and subnets.
  • Select the security group that we created.

EFS

  • Click Next, review and create file system.

Step2: Mount filesystem on running EC2 instance

  • For mounting the EFS filesystem on running EC2 instance first allow traffic on NFS port in EFS security group from EC2 instance security group.
  • Go to security groups. Select the EFS security group that we created earlier. Click Edit Inbound rules.
  • Select NFS port 2049 and running EC2 instance security group as the source.

  • Now login to your running instance.
  • Next, we need to install the Amazon EFS client. For installing EFS Client in the Red Hat Linux server follow these steps.
  • Install git using the following command:
sudo yum -y install git
  • Install the rpm-build package using the following command:
sudo yum -y install rpm-build
  • Clone amazon-efs-utils from GitHub using the following command:
git clone https://github.com/aws/efs-utils
  • Now go to the directory that contains the amazon-efs-utils package:
cd /path/efs-utils
  • Install the bash make command if your OS doesn’t already have it as follows:
sudo yum -y install make
  • Build the amazon-efs-utils package using the following command:
sudo make rpm
  • Install the amazon-efs-utils package with the following command.
sudo yum -y install ./build/amazon-efs-utils*rpm
  • Now create a directory where you want to mount EFS. We will mount the EFS in /mnt/efs/chkmtfs.
cd /mnt sudo mkdir efs cd efs sudo mkdir chkmtfs
  • Now go to the Elastic File System console. Select the file system that we created.

  • Click Attach. We will mount the file system using the mount helper. Copy the command and change the mount directory to /mnt/efs/chkmtfs.

  • Run the following command on the terminal.
sudo mount -t efs -o tls fs-0f36fbc9e3308de74:/ /mnt/efs/chkmtfs
  • Validate the filesystem with the mount command.

EFS

Step3: Mount the filesystem at the launch of a new instance

  • Go to the EC2 console and click Launch instance.
  • Select the OS and instance type.
  • Before adding EFS first we need to add select the subnet for EC2 instance.
  • After selecting the subnet go to storage and select EFS.

EFS

  • Click on Add shared file system.

EFS

  • Click Launch instance.
  • Login to the server and after some time you will see the file system mounted on the /mnt/efs/chkmtfs directory.
  • Now we have two EC2 instances sharing the same Elastic File System.

Please contact our technical consultants if you have anything related to cloud infrastructure to be discussed.

Leave a Reply

Your email address will not be published.

*