In one of our client applications, we use WebRTC Media server which records the peer videos of candidates on server. We create multiple instances of WebRTC Media server in auto scaling mode as load increases. We needed a shared file system which 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 usecase.

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 AWS EFS Service page and create a file system there. You can keep defaults or set as per your needs. Make a note of file system id created
  3. On your ec2 instance, if you have 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 following command
sudo mount -t efs fs-3b068bea:/ /home/ubuntu/janus_recordings/

Above step should mount EFS file sytem to your EC2 istance's directory

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

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

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