Table of Contents
A step-by-step guide on how to mount Elastic File System (EFS) on AWS EC2 instances.
Architecture Diagram
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-58-1024x463.png)
Step 1. Launch Two EC2 Instances
a. Launch an EC2 instance with the following configuration.
Name: MyEC2-1
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-59.png)
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-60.png)
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-61.png)
b. Launch another EC2 instance with the same keypair and security group and name MyEC2-2
c. Wait until the initialization status changes to Running
Step 2. Create an Elastic File System
a. Goto EFS and click Create File System button. On the Pop-Up, click Customize button
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-62.png)
b. Uncheck the option Enable automated backups
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-63-1024x719.png)
c. Network Access Section, remove the Default security group and efs_security_group and click on Next button
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-64-1024x545.png)
d. Leave File System Policy as is, click on the Next button.
e. Review the configuration and click on Create button.
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-65-1024x148.png)
Step 3. Mount the EFS File System to EC2 instances
a. Navigate to EC2 dashboard
b. Select MyEC2-1 and click Connect button
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-66.png)
c. Run the following commands to update the packages and install amazon-efs-util
1 2 3 4 5 |
sudo -s yum -y update yum install -y amazon-efs-utils mkdir efs mkdir aws |
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-70.png)
d. Navigate to EFS Dashboard and click on the file system – MyEFS
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-67-1024x333.png)
d. Click on Attach button and copy the command “Using the EFS mount helper”
1 |
sudo mount -t efs -o tls fs-<your_file_system_id>:/ efs |
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-68-1024x286.png)
e. Paste the above-copied command into the MyEC2-1 terminal
f. Use the following command to display information for all currently mounted file systems.
1 |
df -h |
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-69.png)
g. Repeat step a to h to mount the file system to MyEC2-2 instance.
Step 4. Testing the file system
a. Create a file hello.txt under the efs directory on MyEC2-2 instance
1 2 3 4 |
sudo -s cd efs touch hello.txt ls -ltr |
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-72.png)
b. Go to MyEC2-1, and navigate to the efs directory; you should be able to see the file hello.txt
![](https://www.coddicted.com/wp-content/uploads/2023/06/image-73.png)