DEV Community

Cover image for Elastic File System (EFS) Multi-Instance Deployment: Streamlining File Sharing Across AWS Instances
Oluwole Suliat Adefowoke
Oluwole Suliat Adefowoke

Posted on

Elastic File System (EFS) Multi-Instance Deployment: Streamlining File Sharing Across AWS Instances

In this article, we'll dive into AWS Elastic File System (EFS), a robust storage service that sets itself apart by enabling simultaneous mounting on multiple instances, offering a heightened level of flexibility. If you missed our exploration of Elastic Block Store (EBS), you can find it here.

Now, let's proceed with a comprehensive overview of the steps involved:

1. Create EC2 Instances

Similar to the process for Elastic Block Store (EBS), I provisioned servers with no special configurations, running on eu-north-1b.

Image description.

2. Create File System

In the AWS console, search for Elastic File System service and click on "Create file system".
Image description

Choose between quick creation with default settings or customize for specific configurations
Image description

For customization, follow the detailed steps below:

Step 1: File System Settings
  • File Name: efs-demo
  • File System Type: Regional (redundant across multiple Availability Zones)
  • Automatic Backups: Disable (for now)
  • Lifecycle Management: Default
  • Performance Settings: Default Click on Next.
Step 2: Network Access
  • Specify Mount Targets for each Availability Zone where instances are running.
  • Select the VPC and subnet ID of your instances. (EFS is a VPC specific service)
  • Specify a security group which will act as a firewall for Mount Targets. Click on Next
Step 3: File System Policy

This is very optional setting but you can configure different file system policies if you want but for this demo, we leave as default and proceed to review and create the file system

Image description

3. Mount File System

Access the terminal with connections to both Instances A & B.
Starting with Instance-A, when working with EFS, Amazon has made it really easy if you're using an Amazon Linux Image, you can install a package they created called Amazon-EFS-utils
To install this package, Run sudo yum install -y amazon-efs-utils
Repeat this command on Instance-B.

Now that we installed the EFS package, we want to mount that file system we created in the console.
To see a list of installed efs packages; Run sudo mount. + tab

Image description
We can see a .efs after running that command because we installed the amazon efs utils package.

To mount a file system, you need 2 things

  • efs instance id
  • a folder/directory to mount on To get the efs instance id, go in to the console, click on the efs instance and copy the id as indicated in the image below

Image description

Now that we have all we need, to mount file system, Run sudo mount.efs efs-instance-id /efsdemo/

SIDE NOTE: I went through this so you don't have to

Image description
If encountering mounting errors, ensure that the mount target security group has an inbound rule allowing NFS access from the EC2 security group. Edit the inbound rule accordingly.

Image description

Image description
Once the error is resolved, running df -h should confirm the successful mounting of the file system at /efsdemo.

At this point, we technically can use our EFS file systems but the changes made would not persist through a reboot

4. Persist Data

To ensure data persistence through reboots, open the fstab file using the command sudo nano etc/fstab.
Provide essential details such as the file system ID, the mount point, the file system type, and additional configurations sourced from the AWS EFS Mount Configuration

Image description

After completing these configurations, a system reboot should automatically mount the file system, ensuring seamless data persistence.

To verify the persistence, create a file within the mounted directory using the command:
sudo nano efsfile.txt and input the desired content.

Image description

5.Simultaneous Mount on Instance-B

Unlike EBS, EFS supports simultaneous mounting on multiple instances. Proceed to the second instance and replicate the process performed on Instance-A. Execute the following commands:

sudo mkdir /efsdemo
sudo mount.efs fs-0b058364663762fc9 /efsdemo
df -h
cd /efsdemo/
ls 
cat efsfile.txt
Enter fullscreen mode Exit fullscreen mode

Image description
The successful execution of these commands on Instance-B demonstrates that the file created on Instance-A is accessible on Instance-B.

Image description
Additionally, creating a new file efsfile2.txt on Instance-B is reflected when inspecting the contents on Instance-A.

Image description
This capability underscores the flexibility and convenience offered by AWS Elastic File System for simultaneous data access across multiple instances.

Top comments (0)