How to Mount the Amazon EFS File System on the EC2?

How to Mount the Amazon EFS File System on the EC2?

April 21, 2020 / Nirav Shah

  • Mount the Amazon EFS File System on the EC2
    • Public DNS name of your EC2 instance in the following format:
      • Ec2-xx-xxx-xxx-xx.aws-region.compute.amazonaws.com
    • DNS name of your file system. You can construct this DNS name using the following generic form:
      • File-system-id.efs.aws-region.amazonaws.com
  • Install the NFS Client on Your EC2 Instance
    • Execute the following commands on the EC2 instance by using the SSH session:
    • $ sudo yum -y update
      $ sudo reboot 
    • Install the NFS client.
    • sudo yum -y install nfs-utils
  • Install the NFS Client on Your EC2 Instance
    • Execute the following commands on the EC2 instance by using the SSH session:
    • $ sudo yum -y update
      $ sudo reboot 
    • Install the NFS client.
    • sudo yum -y install nfs-utils
  • Mount File System on Your EC2 Instance
    • Make a directory (“efs-mount-point”).
    • mkdir ~/efs-mount-point
    • Mount the Amazon EFS file system.
    • sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-DNS:/   ~/efs-mount-point
    • The EC2 instance can resolve the mount target DNS name to the IP address. You can optionally specify the IP address of the mount target directly.
    • sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-ip:/  ~/efs-mount-point
    • To check that the mount is done or not
    • cd /efs-mount-point
    • Create a new file
    • sudo mkdir new-file-name
  • How to create a bootstrap script to attach the EFS on launch to an EC2 instance?
    • When we want to implement something without even logging in into an EC2 Instance, then bootstrap scripts can be used in order to achieve that
    • In our case we want to make sure that when we logging to our server our EFS is already connected to the server
    • Also we can attach this bootstrap to launch configuration in an autoscaling which will to maintain the latest updated files in the server
    • Bootstrap Script
    • #/bin/bash
      sudo yum -y update
      sudo yum -y install nfs-utils
      sudo mkdir ~/efs-mount-point
      sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-DNS:/   ~/efs-mount-point
    • Explanation Bootstrap Script
    • #/bin/bash
      • This will make sure that commands are running to the write path
      sudo yum -y update 
      • This will update the server and will have latest dependencies
      sudo yum -y install nfs-utils
      • This will install the NFS client inside the server which will help to connect the EFS file
      sudo mkdir ~/efs-mount-point
      • This will make a directory inside the server to which the EFS will be mounted
      sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-DNS:/   ~/efs-mount-point
      • This is the detail information of the EFS file and path to connect

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let’s Talk About Your Needed AWS Infrastructure Management Services

    Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project