Amazon Elastic Compute Cloud
User Guide for Linux Instances

Amazon Elastic File System (Amazon EFS)

Amazon EFS provides scalable file storage for use with Amazon EC2. You can create an EFS file system and configure your instances to mount the file system. You can use an EFS file system as a common data source for workloads and applications running on multiple instances. For more information, see the Amazon Elastic File System product page.

In this tutorial, you create an EFS file system and two Linux instances that can share data using the file system.


Amazon EFS is not supported on Windows instances.


  • Create a security group (for example, efs-sg) to associate with the EC2 instances and EFS mount target, and add the following rules:

    • Allow inbound SSH connections to the EC2 instances from your computer (the source is the CIDR block for your network).

    • Allow inbound NFS connections to the file system via the EFS mount target from the EC2 instances that are associated with this security group (the source is the security group itself). For more information, see Amazon EFS Rules, and Security Groups for Amazon EC2 Instances and Mount Targets in the Amazon Elastic File System User Guide.

  • Create a key pair. You must specify a key pair when you configure your instances or you can't connect to them. For more information, see Create a Key Pair.

Step 1: Create an EFS File System

Amazon EFS enables you to create a file system that multiple instances can mount and access at the same time. For more information, see Creating Resources for Amazon EFS in the Amazon Elastic File System User Guide.

To create a file system

  1. Open the Amazon Elastic File System console at

  2. Choose Create file system.

  3. On the Configure file system access page, do the following:

    1. For VPC, select the VPC to use for your instances.

    2. For Create mount targets, select all the Availability Zones.

    3. For each Availability Zone, ensure that the value for Security group is the security group that you created in Prerequisites.

    4. Choose Next Step.

  4. On the Configure optional settings page, do the following:

    1. For the tag with Key=Name, type a name for the file system in Value.

    2. For Choose performance mode, keep the default option, General Purpose.

    3. Choose Next Step.

  5. On the Review and create page, choose Create File System.

  6. After the file system is created, note the file system ID, as you'll use it later in this tutorial.

Step 2: Mount the File System

Use the following procedure to launch two t2.micro instances. The user data script mounts the file system to both instances during launch and updates /etc/fstab to ensure that the file system is remounted after an instance reboot. Note that T2 instances must be launched in a subnet. You can use a default VPC or a nondefault VPC.


There are other ways that you can mount the volume (for example, on an already running instance). For more information, see Mounting File Systems in the Amazon Elastic File System User Guide.

To launch two instances and mount an EFS file system

  1. Open the Amazon EC2 console at

  2. Choose Launch Instance.

  3. On the Choose an Amazon Machine Image page, select an Amazon Linux AMI with the HVM virtualization type.

  4. On the Choose an Instance Type page, keep the default instance type, t2.micro and choose Next: Configure Instance Details.

  5. On the Configure Instance Details page, do the following:

    1. For Number of instances, type 2.

    2. [Default VPC] If you have a default VPC, it is the default value for Network. Keep the default VPC and the default value for Subnet to use the default subnet in the Availability Zone that Amazon EC2 chooses for your instances.

      [Nondefault VPC] Select your VPC for Network and a public subnet from Subnet.

    3. [Nondefault VPC] For Auto-assign Public IP, choose Enable. Otherwise, your instances do not get public IP addresses or public DNS names.

    4. Under Advanced Details, select As text, and paste the following script into User data. Update FILE_SYSTEM_ID with the ID of your file system. You can optionally update MOUNT_POINT with a directory for your mounted file system.

      #!/bin/bash yum update -y yum install -y nfs-utils FILE_SYSTEM_ID=fs-xxxxxxxx AVAILABILITY_ZONE=$(curl -s ) REGION=${AVAILABILITY_ZONE:0:-1} MOUNT_POINT=/mnt/efs mkdir -p ${MOUNT_POINT} chown ec2-user:ec2-user ${MOUNT_POINT} echo ${FILE_SYSTEM_ID}.efs.${REGION} ${MOUNT_POINT} nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev 0 0 >> /etc/fstab mount -a -t nfs4
    5. Advance to Step 6 of the wizard.

  6. On the Configure Security Group page, choose Select an existing security group and select the security group that you created in Prerequisites, and then choose Review and Launch.

  7. On the Review Instance Launch page, choose Launch.

  8. In the Select an existing key pair or create a new key pair dialog box, select Choose an existing key pair and choose your key pair. Select the acknowledgment check box, and choose Launch Instances.

  9. In the navigation pane, choose Instances to see the status of your instances. Initially, their status is pending. After the status changes to running, your instances are ready for use.

Step 3: Test the File System

You can connect to your instances and verify that the file system is mounted to the directory that you specified (for example, /mnt/efs).

To verify that the file system is mounted

  1. Connect to your instances. For more information, see Connect to Your Linux Instance.

  2. From the terminal window for each instance, run the df -T command to verify that the EFS file system is mounted.

    $ df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/xvda1 ext4 8123812 1949800 6073764 25% / devtmpfs devtmpfs 4078468 56 4078412 1% /dev tmpfs tmpfs 4089312 0 4089312 0% /dev/shm efs-dns nfs4 9007199254740992 0 9007199254740992 0% /mnt/efs

    Note that the name of the file system, shown in the example output as efs-dns, has the following form:
  3. (Optional) Create a file in the file system from one instance, and then verify that you can view the file from the other instance.

    1. From the first instance, run the following command to create the file:

      $ sudo touch /mnt/efs/test-file.txt
    2. From the second instance, run the following command to view the file:

      $ ls /mnt/efs test-file.txt

Step 4: Clean Up

When you are finished with this tutorial, you can terminate the instances and delete the file system.

To terminate the instances

  1. Open the Amazon EC2 console at

  2. In the navigation pane, choose Instances.

  3. Select the instances to terminate.

  4. Choose Actions, Instance State, Terminate.

  5. Choose Yes, Terminate when prompted for confirmation.

To delete the file system

  1. Open the Amazon Elastic File System console at

  2. Select the file system to delete.

  3. Choose Actions, Delete file system.

  4. When prompted for confirmation, type the ID of the file system and choose Delete File System.