Skip to main content
In this lesson, we demonstrate how to deploy and use AWS Elastic File System (EFS), highlighting its benefits such as mounting the same file system on multiple EC2 instances. This guide complements our previous Elastic Block Store demo by focusing on a shared file system accessible by multiple machines.

Overview

This demo uses two EC2 instances running in the US East 1C Availability Zone. Our objective is to create an EFS file system and mount it on both instances. One of the key advantages of EFS is its ability to allow concurrent access by multiple instances. First, verify that your EC2 instances (instance one and instance two) are up and running in US East 1C. Once confirmed, proceed with creating the Elastic File System.
The image shows an AWS EC2 dashboard with two running instances, both of type t2.micro, in the us-east-1c availability zone.

Creating the EFS File System

  1. In the AWS Management Console, search for the Elastic File System service.
  2. Click Create File System. You can choose the default quick creation option or select Customize to adjust detailed settings:
    • Provide a name (e.g., “EFS Demo”).
    • Choose the storage class:
      • Standard: Ensures redundancy across multiple Availability Zones.
      • One Zone: Stores the file system in a single Availability Zone.
The image shows the AWS EFS file system settings page, where users can configure general settings, storage class, automatic backups, lifecycle management, and encryption options.
  1. For this demonstration, disable automatic backups, choose lifecycle settings as needed, and leave encryption disabled. Use the default throughput mode.
  2. Click Next.
The image shows an AWS management console screen for configuring EFS settings, including lifecycle management, encryption, and performance settings with options for throughput modes.

Configuring Mount Targets

Mount targets expose your EFS file system to the instances within your VPC. They are required in every Availability Zone that houses servers needing access.
  1. Since both instances are in US East 1C, remove any other availability zones if present.
  2. Select the subnet corresponding to US East 1C.
  3. Specify a security group (e.g., one named “EFS”) that permits access from your EC2 instances.
  4. Confirm the correct VPC is selected.
  5. Click Next.
The image shows an AWS console screen for configuring network access, including VPC selection and mount targets for Amazon EFS across different availability zones.

Setting File System Policies

Set file system policies to control access—options include preventing root access or enforcing read-only mode. For this demo, leave the defaults.
The image shows an AWS EFS file system policy configuration screen with options for access control and encryption settings.
Review your settings and click Create. The file system will initially appear in a “creating” state. Refresh the page until it becomes available.
The image shows an AWS Elastic File System dashboard with one available file system named "efsdemo," unencrypted, and a total size of 6.00 KiB.

Preparing the EC2 Instances

For both instances, install the Amazon EFS Utils package to simplify mounting EFS on Amazon Linux images. On instance 1 (apply the same on instance 2), run:
The output will display information similar to the following:

Mounting the EFS File System

Step 1: Create the Mount Directory

On instance 1, create a directory where the EFS file system will be mounted:

Step 2: Mount the EFS File System

To mount the EFS file system, use the mount.efs command with two arguments:
  • The EFS file system ID (copy it from your AWS console under EFS details).
  • The target directory (e.g., /efsdemo).
For example, on instance 1, execute:
Verify the mount by running:
Expected output:
Ensure you create the mount directory only once before executing the mount command with the correct file system ID.

Step 3: Make the Mount Persistent

To automatically mount the file system after a reboot, update the /etc/fstab file. Add a new line with your file system ID and mount point:
An example /etc/fstab file:
After modifying /etc/fstab, mount all file systems with:
Then, verify the mount using:

Sharing Files Between Instances

To test the shared file system, create a file on instance 1 in the /efsdemo directory:
For instance, add the content:
Next, perform the following on instance 2:
  1. Create the mount directory (if it doesn’t exist yet):
  2. Mount the EFS file system using the same command as on instance 1:
  3. Verify the mount:
  4. Navigate to /efsdemo and verify that file1.txt exists:
  5. Optionally, create another file on instance 2:
    Add the content:
  6. Return to instance 1 to ensure both files are visible:
This verifies that changes on one instance are visible on the other, showcasing the sharing capability of AWS EFS.

Cleaning Up

To conclude the demo, delete the EFS file system through the AWS console:
  1. Select your EFS file system and click Delete.
  2. When prompted, copy the file system name, paste it into the confirmation box, and confirm deletion.
The image shows an AWS console screen with a prompt to confirm the deletion of a file system, warning that this action is irreversible.
After a few minutes, the file system will be successfully deleted.
This demonstration covers creating, mounting, and using AWS EFS across multiple EC2 instances. For more information on AWS EFS configuration and best practices, refer to the AWS Documentation.

Watch Video