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


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
- Sign in to AWS Management Console: Ensure you have the necessary permissions to create and manage resources.
2. Launch EC2 Instances
Open EC2 Dashboard: Navigate to the EC2 dashboard.
Launch Two EC2 Instances: Choose the instance type, configure the instance details, add storage, and configure security groups to allow necessary traffic.
Assign Name: Give a name to your EC2 instance for easy identification(CloudNative1, CloudNative2).
3. Create and Configure EFS
Open EFS Dashboard: Navigate to the EFS dashboard.
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
- 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
- Connect to EC2 Instances: Use SSH to connect to each EC2 instance.
Click on the connect button again to Launch the Instance
when the instance is connected, it redirects you to your terminal
Install NFS Client: Install the NFS client on both instances using the following command:
sudo yum install -y nfs-utils
Create Mount Point: Create a directory to mount the EFS file system. For example:
sudo mkdir /mnt/efs
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 andREGION
with your AWS region.fs-XXXXXXXX.efs.REGION.amazonaws.com:/ /mnt/efs nfs4 defaults,_netdev 0 0
- 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.
Subscribe to my newsletter
Read articles from Joel Thompson directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
