Deploying EC2 instances with shared EFS storage to ensure file sharing in real time.

Joel ThompsonJoel Thompson
2 min read

Deploying EC2 Instances with Shared EFS Storage

In the ever-evolving landscape of cloud computing, ensuring seamless collaboration and data sharing across distributed applications is paramount. This guide delves into the practical steps required to configure Amazon Elastic File System (EFS) for real-time file sharing between two Amazon EC2 instances. By achieving this, you guarantee synchronized data access and storage, which is critical for maintaining the performance and integrity of your distributed application.


Now, let's move on to the steps involved:

Steps to Deploy EC2 Instances with Shared EFS Storage

1. Set Up Your Environment

  1. Sign in to AWS Management Console: Ensure you have the necessary permissions to create and manage resources.

2. Launch EC2 Instances

  1. Open EC2 Dashboard: Navigate to the EC2 dashboard.

  2. Launch Two EC2 Instances: Choose the instance type, configure the instance details, add storage, and configure security groups to allow necessary traffic.

  3. Assign Name: Give a name to your EC2 instance for easy identification(CloudNative1, CloudNative2).

3. Create and Configure EFS

  1. Open EFS Dashboard: Navigate to the EFS dashboard.

  2. Create EFS File System: Create a new EFS file system. Select the VPC and subnets where your EC2 instances are located.

Take Note of The EFS Mount Helper link which will be needed later

  1. Configure Security Groups: Ensure the security groups for your EFS allow NFS (Network File System) traffic from your EC2 instances.

Click on DEFAULT SG and select EDIT IMBOUND RULES

Select NFS as TYPE, Instance Name (CloudNative1) as SOURCE

4. Attach EFS to EC2 Instances

  1. Connect to EC2 Instances: Use SSH to connect to each EC2 instance.

Click on the connect button again to Launch the Instance

  1. when the instance is connected, it redirects you to your terminal

  2. Install NFS Client: Install the NFS client on both instances using the following command:

     sudo yum install -y nfs-utils
    

  3. Create Mount Point: Create a directory to mount the EFS file system. For example:

     sudo mkdir /mnt/efs
    
  4. Mount EFS: Mount the EFS file system to the directory using:

     sudo mount -t nfs -o nfsvers=4.1 fs-XXXXXXXX.efs.REGION.amazonaws.com:/ /mnt/efs
    

    Replace fs-XXXXXXXX with your EFS file system ID and REGION with your AWS region.

  5.  fs-XXXXXXXX.efs.REGION.amazonaws.com:/ /mnt/efs nfs4 defaults,_netdev 0 0
    

    hi

  1. The same file created in instance 2(Index.html) will now reflect in Instance 1

By following these steps, you'll be able to configure AWS storage solutions, manage security groups, and ensure high availability for your distributed application.

0
Subscribe to my newsletter

Read articles from Joel Thompson directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Joel Thompson
Joel Thompson