How to create EFS in AWS and Mount on EC2 Instance

This post is on how to setup an AWS EFS file system and most importantly how this can be accessed(mounted) by 2 EC2 instances simultaneously.

If you want to know to How to launch an EC2 instance, please click ‘How to Launch my first EC2 Instance‘. It is must to have at least 2 EC2 instances either before or after creating EFS, to test it out.

  1. EFS is available under Storage Services.

 

2. Click on Create file system, which will take us to configure file system. Select your VPC, AZ (which AZ’s this can be mounted on,by default all will be checked) and Security Group and then click next.

 

3. If you want to Add tags for your reference, select performance mode – default ‘General Purpose’ , select throughput – default Bursting, Enable Encryption – default unchecked and then click on next.

 






4. Review & create the EFS.

5. It will take a couple minute  to create the EFS. You will see ip address, which will be used to mount from EC2 instance.


6. Now go to your EC2 if already created, else launch a new EC2 instance follow the below,

  • ¬†Launch your first EC2 Instance.
  • Go to mount point directory.
    • cd /mnt
  • Create a directory where this EFS will need to be mounted.
    • mkdir dummyefs
  • Now use the below command to mount your EFS, note: you will have to replace the ip as per your EFS ip which was created earlier.
    • mount -t nfs4 172.31.7.160:/ /mnt/dummyefs
  • Issue df -h command to see yourself the mounted directory.
  • Create a file and save it, so the same can be accessed from another EC2 instance.

7. Launch your second EC2 instance to get access to the above created file from the EFS mounted point.

  • Again create a Directory.
  • Mount the EFS file system using the mount command.
    • mount -t nfs4 172.31.7.160:/ /mnt/dummyefs
    • Confirm the mount by issuing df -h command.
    • Go to the mount directory and cat for the file which was created by your First EC2 instance.

 

That’s it! we have successfully created EFS mounting on 2 EC2 instances.

Leave a Reply

Your email address will not be published. Required fields are marked *