AWS EFS (Elastic File Storage)
Tags: aws, cloud, cloudcomputing, efs
Published: 2022-03-27 05:42:50

**What is 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.

**Instance store lifetime** 

- You can specify instance store volumes for an instance only when you launch it. You can't detach an instance store volume from one instance and attach it to a different instance.
- The data in an instance store persists only during the lifetime of its associated instance. 
- If an instance reboots, data in the instance store persists. However, data in the instance store is lost under any of the following circumstances:
• The underlying disk drive fails
• The instance stops
• The instance terminates
Therefore, we generally do not rely on instance store for valuable, long-term data. Instead, we use more durable data
storage, such as Amazon S3, Amazon EBS, or Amazon EFS. Here we'll discuss about features and implementation of EFS.

**Characteristics of EFS volume**
- In EFS, we mount the volume in multiple instances like a shared storage.
- EBS volume can only be mounted on AWS Ec2 whereas EFS can be mounted on AWS Ec2, Azure Vms, GCP vms and also on premises servers.
- EFS can be attached with servers irrespective of availability zones.
- For EFS, we don't have to define storage and aws only charges for the storage that's used i.e. EFS is synced with the data copied.
- Amazon EFS is a fully managed service for hosting Network File System (NFS) filesystems in the cloud.
- It is an implementation of a NFS file share and is accessed using the NFS protocol.
- It provides elastic storage capacity and pay for what you use (in contrast to Amazon EBS with which you pay for what you provision).
- You can configure mount-points in one, or many, AZs.
- You can mount an AWS EFS filesystem from on-premises systems ONLY if you are using AWS Direct Connect or a VPN connection.

- Typical use cases include big data and analytics, media processing workflows, content management, web serving, home directories etc.

- AWS EFS can scale up to petabytes. AWS EFS is elastic and grows and shrinks as you add and remove data.

- You can concurrently connect up to thousands of Amazon EC2 instances, from multiple AZs.

The following diagram depicts the various options for mounting an EFS filesystem:

![Amazon EFS File System](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vtj201gvz959mz1s8m6b.jpeg)

**Need for EFS in AWS**
- In EBS, we clubbed ebs volumes and mounted those volumes on a server. 
- But to attach that same volume to another server/instance we have to first unmount the volume from server-1 and then attach vol. to server-2.
- Similarly for multiple servers, we can unmount and detach volume from one server and attach it to another.

![Uses of EFS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b2oulpr8yru0ef89ebn.jpg)

**<u>On premises setup for EBS</u>**

- Load balancers are used to distribute traffic into different servers so that each server can handle requests.
- Data from each server gets stored in the database, we've to give the database an endpoint. If we don't have an database, we can store the data locally.
- Such as let's consider an e-commerce app. If today you accessed the app and you get response from server-1. then your details will be stored in EBS volume of server-1.
- The next day if you access the app and you get response from server-2, then you can't see your details listed over there as server-2 has different EBS volume.
- To solve this issue we use EFS volume and mount it to multiple instances in order to make the app more user friendly.

![EFS vs EBS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqcojz6aqg864r57vwuj.jpeg)

**<u>On premises setup For EFS :</u>**

- ![On prem setup of EFS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ur79bj4edoddkqrmpyus.jpg)
-First we establish a hardware rack and then mount hardware on it.
- Linux and NFS are configured on the servers.
- Then we attach the server to SAN storage by a LAN cable. 
- NFS basically converts the physical volumes into logical volumes. So that we can attach the logical volumes into different servers. Changes in each server gets reflected on logical volumes.
- But, On premises setup is costly, so Aws provides these services as functionality of NFS using EFS.

**EFS VS EBS**
We often get confused about EFS and EBS volumes and their characteristics. Here I've mentioned some basic and key differences between ebs and efs.

1. EBS can be mounted on EC2 instances only. Whereas, EFS can be mounted on Virtual machine(VMs) of AZURE, Compute engines of GCP, and also with the on premises setup too.

2. For EBS, the instance attached with ebs should be in the same availability zone as that of the ebs vol. If not, then we've to create a snapshot of ebs in the same region as that of instance and attach it.
But in case of EFS, the efs vol can be attached to instance irrespective of the availability zone specified.

3. If we use 10 GB of EBS volume, AWS charges us for the entire 10GB, even if all of it isn't utilized.
But in EFS volume we don't specify the storage. Rather, it is synced with the data copied. Which means, if you use 1GB of data then you'll be charged for that 1GB only.
So, EFS is cost effective than EBS.

![ebs vs efs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5jqcmadbkjglzj4aimk.PNG)

**PROVISIONING:**
- Launch an ec2 instance with security group configured to allow only your IP to ssh into the server.
- To mount EFS on server, we need to allow NFS port i.e, port 2049.

![NFS config](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/36jv7d26ka0xutpngv5x.png)
- Now go to EFS on AWS console and  create a file system. For the network part click manage -> security groups -> select the security group you configured (say my-sg) and save the changes.
- Here you can choose any availability zone for your efs vol. configuration. (My instance is at ap-south-1a and I've configured my efs vol. at ap-south-1b).

![EFS config](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pd62ejyt35qpfsvqf2es.png)
- 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oamnsw6raexmh7880b8x.png)

- After configuring network part, click on attach -> mount via ip. Then copy the command to attach efs via nfs.
- Run the command in xshell

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdxuxsv1bah3l2qmabqy.png)
-After mounting the volume create some files in the instance "my-server" by using touch command.
- Similarly, if we create two instances (VM-1, and VM-2) and configure efs volume via NFS client following the above steps,
we've to connect both the instances separately and mount the efs volume by creating a folder (say mkdir  /efs1 or mkdir /efs2 respectively.)
- Now if we create some files on VM-1 by using touch command (say touch abc{1..100}) , these files will also be listed over VM-2 server as we're using the same EFS volume for both the servers.

**CONCUSION:**
- Basically, we learned that in EFS, we can attach volume to multiple servers and if we make changes in one server, then the same changes are reflected on the other servers too.