Hands-On Demo: Creating and Mounting an Amazon EFS File System

In this hands-on tutorial, we’ll guide you through the process of creating an Amazon Elastic File System (EFS) and mounting it to two EC2 instances across two availability zones. EFS is a scalable and highly available file storage service offered by Amazon Web Services (AWS).

Prerequisites

Before you begin, make sure you have an AWS account and are logged in to the AWS Management Console.

Step 1: Create a Security Group

  1. Navigate to the Amazon EC2 Dashboard in the AWS Management Console.
  2. In the left sidebar, under “Network & Security,” click on Security Groups.
  3. Click the Create Security Group button.
    • Security group name: Enter a name for your security group (e.g., “EFS access”).
    • Description: Provide a brief description (e.g., “Allow SSH and NFS”).
    • VPC: Leave it as the default VPC.
  4. For inbound rules, add two rules:
    • Rule 1:
      • Type: SSH
      • Source: 0.0.0.0/0 (for SSH access from anywhere)
    • Rule 2:
      • Type: NFS (You may need to type “NFS” and select the protocol)
      • Source: Start typing “sg” to select the security group you just created. This allows access to NFS from instances associated with this security group.
  5. Click Create security group.

Step 2: Launch Two EC2 Instances

  1. In the AWS EC2 Dashboard, click Instances in the left sidebar.
  2. Click the Launch Instances button.For both instances:
    • Choose an Amazon Machine Image (AMI) of your choice (e.g., Amazon Linux 2).
    • Choose an instance type (e.g., t2.micro).
    • Configure instance details:
      • Choose your existing security group (“EFS access”).
      • Choose different subnets within different availability zones (e.g., US East 1A and US East 1B).
    • Leave all other settings as default.
    • Launch the instances without a key pair (if you don’t plan to SSH into them).

Step 3: Create an Amazon EFS File System

  1. In the AWS EFS Dashboard, click Create file system.
  2. Choose the default VPC.
  3. Leave the standard storage class selected.
  4. Optionally, give your file system a name.
  5. Click Create file system.

Your EFS file system will take a few minutes to create. Once it’s ready, click on the file system to view its details.

Step 4: Configure EFS Mount Targets

  1. Click on the Network tab within the EFS file system details.
  2. You’ll see the file system’s DNS name. Copy this DNS name for later use.

Step 5: SSH into EC2 Instances

  • Use EC2 Instance Connect to SSH into both of your EC2 instances. Make sure you can access both instances.

Step 6: Mount the EFS File System

We have two methods for mounting the EFS file system: using the standard NFS client or the AWS EFS utilities.

Method 1: Using the Standard NFS Client

On both instances, perform the following steps:

  1. Update the package manager:
sudo yum update -y
  1. Install NFS utilities:
sudo yum install -y nfs-utils
  1. Mount the EFS file system. Replace <your-DNS-name> with the DNS name you copied earlier:
sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 <your-DNS-name>:/ /efs-mount-point

Method 2: Using AWS EFS Utilities

On both instances, perform the following steps:

  1. Update the package manager:
sudo yum update -y
  1. Install the Amazon EFS utilities package:
bashCopy codesudo yum install -y amazon-efs-utils
  1. Mount the EFS file system using the EFS mount helper:
sudo mount -t efs <your-file-system-ID>:/ /efs-mount-point

Replace <your-file-system-ID> with your EFS file system ID.

Step 7: Test the File System

On both instances, navigate to the EFS mount point and create a test directory and file:

cd /efs-mount-point
sudo mkdir test-directory
sudo touch test-file

Step 8: Verify Data Access

Switch to the other EC2 instance and navigate to the EFS mount point to check if you can see the data created on the first instance:

cd /efs-mount-point
ls

You should see the test-directory and test-file created on the first instance. This confirms that both instances are successfully accessing the same EFS file system.

Step 9: Cleanup

Once you have completed your testing, make sure to terminate your EC2 instances and delete the EFS file system to avoid ongoing charges.

  1. Terminate your EC2 instances in the EC2 Dashboard.
  2. In the EFS Dashboard, select your file system, click Actions, and then choose Delete file system. Confirm the deletion.

Congratulations! You’ve successfully created an Amazon EFS file system and mounted it to two EC2 instances across different availability zones, demonstrating the high availability and scalability of EFS for shared file storage in AWS.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top