Skip to content

EFS – Even Simpler Than S3

A newer service recently introduced into the AWS storage portfolio is Elastic File System or EFS. Announced in 2015 and made available for production use in 2016, it provides the ability to mount shared storage to multiple EC2 instances.

It’s a fully-managed file system service with low latency that grows and shrinks as needed. With Elastic Block Store (EBS), you have to provision a certain amount of storage or bandwidth ahead of time, but EFS is designed for simplicity, allowing you to grow to petabyte scale without pre-provisioning. As is common with AWS, the data is also redundantly stored across multiple availability zones and made highly available.

EFS is arguably even simpler than S3, Amazon’s “Simple” Storage Service. All you have to do is create a file system and then set up a “mount target” in each availability zone where EC2 instances will be mounting it. Note that only one mount target can exist in each AZ and they are assigned to subnets within your VPC.

To get started, hop over to the AWS console, choose a region, go to EFS, and click on “Create file system”. You’ll see the following:

First, you choose a VPC containing the subnets you’d like to create mount targets in. As a reminder, every subnet is specific to a particular AZ. You can choose to create mount targets in each AZ or only in the ones from which you’ll be mounting. You can assign security groups to each mount target (use inbound TCP port 2049 for the underlying NFSv4.1 protocol). Optionally, you can assign a specific private IP address rather than automatically assigning one from the subnet’s CIDR block. Click “Next Step” to move on to the next page:

On this page, you can optionally tag the file system and choose a performance mode. General purpose is the default mode and is recommended by AWS unless you expect to have “tens, hundreds, or thousands of EC2 instances accessing the file system concurrently”. Check this page out if you’d like more details.

Click “Next Step” to move on to the review page and make sure everything looks good:

Click “Create File System” and you’re done!

Now, in order to mount the file system to an EC2 instance, you’ll use standard linux mounting commands. Note that EFS does not currently work with Windows EC2 instances. You can mount the file system by referring to the DNS name of a mount target in the same AZ or by using the DNS name of the file system itself, a recently introduced feature. This latter approach is simpler and will be the approach that we’ll take here.

The file system DNS name automatically resolves to the mount target’s IP address in the AZ of the instance from which we’re mounting. You can get the DNS name from the AWS console or construct it using the following:

The following command adds the file system to the /etc/fstab file, causing it to be mounted automatically on system boot. Note that you’ll need to replace file-system-id, aws-region, and /nas/content/live/l1strategy/efs-mount-point with the correct values. You’ll also want to make sure that the mount point folder already exists on the instance. Run the command as root:

echo “ /nas/content/live/l1strategy/efs-mount-point nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0” >> /etc/fstab

With the fstab file updated, we can use the following to mount the file system manually (so we don’t have to reboot):

mount -a -t nfs4

And with that we have an elastic file system that can grow and shrink as needed. A few things to be aware of:

  • If you’re not using the latest Amazon Linux AMI, you may need to install an NFS client (nfs-utils or nfs-common packages for yum and apt-get, respectively).
  • Pricing is based on the amount of storage used each month.
  • Unlike EBS, you can’t take snapshots of elastic file systems. You’ll need to explore different approaches for backup.