AWS Cloud Quest: EFS mount on EC2



This content originally appeared on DEV Community and was authored by JJ Chen

🚩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
# download aws efs utils
sudo yum install -y Amazon-efs-utils
# create folder
mkdir data
# paste from "Attach" button
sudo mount -t efs -o tls fs-id:/ data
cd data
# write text in file
sudo bash -c “cat >> efs-1-setup.log”
# cat -> output "efs-1-setup.log"

efs-1 mounted in site A

cat efs-1-setup.log

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.


This content originally appeared on DEV Community and was authored by JJ Chen