Setting Up AWS EFS and Mounting It to Multiple EC2 Instances

By Łukasz Kallas
Picture of the author
Published on
aws image

Amazon Elastic File System (EFS) is a fully managed, scalable file storage service designed to be used with Amazon EC2. It allows multiple instances to share data easily by providing a file system that can be mounted across different EC2 instances.

Steps to Create and Mount AWS EFS

  1. Create an EFS File System:

    • Go to the AWS Management Console.
    • Navigate to EFS (Elastic File System).
    • Click Create file system.
    • Choose the appropriate VPC and subnets. Ensure that your EC2 instances are in the same VPC.
    • Configure security groups and permissions for access to the file system.
    • Click Create to complete the EFS creation.
  2. Launch Two EC2 Instances:

    • Navigate to the EC2 Dashboard.
    • Launch two EC2 instances in the same VPC and subnets that were used for the EFS.
    • Make sure both instances have appropriate IAM roles and security groups to allow NFS (Network File System) traffic.
  3. Mount the EFS on Both EC2 Instances:

    • SSH into your first EC2 instance.
    • Create a directory to mount the EFS:
      sudo mkdir /efs
      
    • Use the command taken from EFS -> Attach section in AWS.
    • Repeat the same steps for the second EC2 instance to mount the same EFS.
  4. Verify Shared Access:

    • On the first EC2 instance, create a file inside the /efs directory:
      echo "Hello from instance 1" > /efs/shared-file.txt
      
    • On the second EC2 instance, check if the file exists inside /efs:
      cat /efs/shared-file.txt
      

    Both instances should have access to the same file, confirming that the data is shared between them.

Stay Tuned

Want to learn?
The best articles, links and news related to software development delivered once a week to your inbox.