How to mount Amazon EFS file system to EC2 instance

In one of our client applications, we use the WebRTC Media server which records the peer videos of candidates on the server. We create multiple instances of WebRTC Media server in auto scaling mode as load increases. We needed a shared file system that can scale so that we can store the video files concurrently without hassle. We also upload the stored files using our application service to Amazon S3. Let's see how can we leverage AWS's EFS service for this use case.

Amazon EFS provides file storage in the AWS Cloud. With Amazon EFS, you can create a file system, mount the file system on an Amazon EC2 instance, and then read and write data to and from your file system.

You can access your Amazon EFS file system concurrently from multiple NFS clients, so applications that scale beyond a single connection can access a file system.

Steps

  1. On your instance, download and install efs-utils from https://github.com/aws/efs-utils
  2. Go to the AWS EFS Service page and create a file system there. You can keep defaults or set them as per your needs. Make a note of the file system id created
  3. On your ec2 instance, if you have an existing security group add a rule to allow inbound traffic to the NFS port (2049) from your on-premises server. Else create a new security group with this rule.
  4. Create a new IAM Role with AmazonElasticFileSystemFullAccess or with a bit different permissions as per your rule. Attach this IAM Role by going to Instant Settings, Attach/Replace IAM role
  5. Create a directory where you want to mount the EFS volume, in my case it's /home/ubuntu/janus_recordings
  6. To mount the EFS to the created directory run the following command
sudo mount -t efs fs-3b068bea:/ /home/ubuntu/janus_recordings/

The above step should mount the EFS file system to your EC2 instance's directory

7. To automatically mount the EFS volume, event after reboots, add the following line to /etc/fstab file.

fs-3b068bea:/ /home/ubuntu/janus_recordings/ efs _netdev,tls,iam 0 0

8. Now even after a reboot, you can see EFS volume mounted to your EC2 instance

Anil Wadghule

Anil Wadghule