DEV Community

Cover image for AWS Cloud Quest🎮: EFS mount on EC2
JJ Dev
JJ Dev

Posted on • Edited on

AWS Cloud Quest🎮: EFS mount on EC2

Topic: File Systems in the Cloud

🚩issue: Web servers in different Availability Zones need to access the same file data.

EFS mount on EC2

Step 1. Create security groups for EFS✨

Create security groups for EFS → Allow web servers to access EFS

  • Security Group:Acts as a virtual firewall, used to control inbound and outbound traffic for EC2 instances. Can be used within an existing VPC.
  1. In the lab, choose VPC of PetModelsWebServer.

  2. Set the NFS type in the Inbound Rule of the Security Group of EFS

  3. Choose the Security Group of PetModelsWebServer as source
    Only resources belonging to the Web server Security Group are allowed to access EFS

  • By selecting a security group as the incoming source, any EC2 instances linked to the security group you select will have NFS client access to the file system.

Step 2. Create an EFS✨

  1. Create File System on the EFS security group

  2. Set network access to allow mount Target
    - Az-1 to EFS security groups
    - Az-2 to EFS security groups
    - Az-3 to EFS security groups

  3. click Attach button to copy mount command

Step 3. EC2 mount NFS✨

Ok! Now, all environments are ready.
You will mount a /data folder on EC2.
The following are the command for mounting a NFS in Linux

sudo -i
Enter fullscreen mode Exit fullscreen mode
# download aws efs utils
sudo yum install -y Amazon-efs-utils
Enter fullscreen mode Exit fullscreen mode
# create folder
mkdir data
Enter fullscreen mode Exit fullscreen mode
# paste from "Attach" button
sudo mount -t efs -o tls fs-id:/ data
Enter fullscreen mode Exit fullscreen mode
cd data
Enter fullscreen mode Exit fullscreen mode
# write text in file
sudo bash -c “cat >> efs-1-setup.log”
Enter fullscreen mode Exit fullscreen mode
# cat -> output "efs-1-setup.log"

efs-1 mounted in site A

Enter fullscreen mode Exit fullscreen mode
cat efs-1-setup.log
Enter fullscreen mode Exit fullscreen mode

Step 4. Repeat Step 3. for each EC2✨

After setting, you can read and write files from other EC2s.
All changes will be synchronized with EFS.

Top comments (0)