Menu
Amazon Elastic File System
User Guide

Step 3: Mount the Amazon EFS File System on the EC2 Instance and Test

In this step, you do the following:

  • Install an NFS client on your EC2 instance.

  • Mount the file system on your EC2 instance and test the setup.

Step 3.1: Gather Information

Make sure you have the following information as you follow the steps in this section:

  • Public DNS name of your EC2 instance in the following format:

    Copy
    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:

    Copy
    file-system-id.efs.aws-region.amazonaws.com

    The EC2 instance on which you mount the file system by using the mount target can resolve the file system's DNS name to the mount target's IP address.

Note

Amazon EFS doesn't require that your Amazon EC2 instance have either a public IP address or public DNS name. The requirements listed preceding are just for this walkthrough example to ensure that you'll be able to connect by using SSH into the instance from outside the VPC.

Step 3.2: Install the NFS Client on Your EC2 Instance

You can connect to your EC2 instance from Windows or from a computer running Linux, or Mac OS X, or any other Unix variant.

To install an NFS client

  1. Connect to your EC2 instance:

    • To connect to your instance from a computer running Mac OS or Linux, you specify the .pem file to your ssh command with the -i option and the path to your private key.

    • To connect to your instance from a computer running Windows, you can use either MindTerm or PuTTY. If you plan to use PuTTY, you need to install it and use the following procedure to convert the .pem file to a .ppk file.

    For more information, see the following topics in the Amazon EC2 User Guide for Linux Instances:

  2. Execute the following commands on the EC2 instance by using the SSH session:

    1. (Optional) Get updates and reboot.

      Copy
      $ sudo yum -y update $ sudo reboot

      After the reboot, reconnect to your EC2 instance.

    2. Install the NFS client.

      Copy
      $ sudo yum -y install nfs-utils

      Note

      If you choose the Amazon Linux AMI 2016.03.0 Amazon Linux AMI when launching your Amazon EC2 instance, you won't need to install nfs-utils because it is already included in the AMI by default.

Step 3.3: Mount File System on Your EC2 Instance and Test

Now you mount the file system on your EC2 instance.

  1. Make a directory ("efs-mount-point").

    Copy
    $ mkdir ~/efs-mount-point
  2. Mount the Amazon EFS file system.

    Copy
    $ sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 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.

    Copy
    $ sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 mount-target-ip:/  ~/efs-mount-point
  3. Now that you have the Amazon EFS file system mounted on your EC2 instance, you can create files.

    1. Change the directory.

      Copy
      $ cd ~/efs-mount-point
    2. List the directory contents.

      Copy
      $ ls -al

      It should be empty.

      Copy
      drwxr-xr-x 2 root root 4096 Dec 29 22:33 . drwx------ 4 ec2-user ec2-user 4096 Dec 29 22:54 ..
    3. The root directory of a file system, upon creation, is owned by and is writable by the root user, so you need to change permissions to add files.

      Copy
      $ sudo chmod go+rw .

      Now, if you try the ls -al command you see that the permissions have changed.

      Copy
      drwxrwxrwx 2 root root 4096 Dec 29 22:33 . drwx------ 4 ec2-user ec2-user 4096 Dec 29 22:54 ..
    4. Create a text file.

      Copy
      $ touch test-file.txt
    5. List directory content.

      Copy
      $ ls -l

You now have successfully created and mounted an Amazon EFS file system on your EC2 instance in your VPC.

The file system you mounted will not persist across reboots. To automatically remount the directory you can use the fstab file. For more information, see Automatic Remounting on Reboot. If you are using an Auto Scaling group to launch EC2 instances, you can also set scripts in a launch configuration. For an example, see Walkthrough 2: Set Up an Apache Web Server and Serve Amazon EFS Files.

Next Step

Step 4: Clean Up