# Mount Elastic File System (EFS) on EC2 Instance (Hands-On)

This lab walks you through mounting EFS on EC2 Instances.  

## Amazon Elastic File System  

- **Fully managed File Storage** for Linux with NFS v4.0, v4.1 support 
- **Highly Available and Durable** : 99.999999999 percent (11 9s) of durability and up to 99.99 percent (4 9s) of availability. 
- **Elastic and Scalable**: EFS automatically grows & shrinks as you add and remove files with no need for manual intervention.  
- Storage Classes and Lifecycle Management  
The Amazon EFS Standard-Infrequent Access (EFS Standard-IA) and Amazon EFS One Zone-Infrequent Access (EFS One Zone-IA) Storage Classes are cost-optimized for files accessed less frequently.  
EFS Lifecycle Management saves cost by applying age-off policy (7, 14, 30, 60, or 90 days).  
- Two Performance Modes:  
**General Purpose** :  sub-millisecond read latency and low single-digit millisecond write latency.  
**Max I/O **:  scales to higher levels of aggregate throughput and operations per second, which is ideal for highly parallelized applications
- Two Throughput Modes:  
**Bursting:**  throughput scales with the size of the file system, dynamically bursting as needed.  
**Provisioned: **  is designed to support applications that require higher dedicated throughput than the default Bursting mode and it can be configured independently of the amount of data stored
- Encryption to both Data at Rest and Data in Flight.   
Data at Rest by the AWS Key Management Service (AWS KMS)  
Data in transit uses industry-standard Transport Layer Security (TLS) to secure network traffic
- With elastic capacity, provisioning is unnecessary, and you’re billed only for what you use.

### Hands-On Tutorial : We will go over How to Mount EFS on Linux EC2 Instance step-by-step

1. Open AWS Console , Search EFS and Create a EFS File Storage 
![screely-1656479414045.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656479548861/rBXs1Wyk_.png align="left")

2. File Storage's Customizable Settings
![screely-1656479422638.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656479562451/7tTPR0bmH.png align="left")
Here we can fully see & customize ALL EFS Features.

3.  After that, Click "Attach" on EFS File System to see mounting Options: Mount via DNS & Mount via IP (any one would work) 
![screely-1656479435237.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656479670430/T5qRn7OFB.png align="left")
![screely-1656479444261.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656479681266/21yDj9_VM.png align="left")
![screely-1656479479335.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656479688196/Je2Jhu_VK.png align="left")  

4. We can Spin up Amazon Linux AMI using "Launch Instance" under EC2 with default settings & SSH into it. [How to here.](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html)  
![screely-1656479510872.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656479832383/244ga5Ux3.png align="left")
Note : When configuring Default / New **Security Group** on EC2, Make sure Port 22 for SSH and **Port 2049** for NFS are Open Inbound Connection from EFS. More on that [here](https://docs.aws.amazon.com/efs/latest/ug/accessing-fs-create-security-groups.html), 
![screely-1656479488256.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656479807337/eotMzbJuc.png align="left")
EFS mount helper requires **" amazon-efs-utils "** package installed on the EC2 instance. Install it by running command, 
```
sudo yum install -y amazon-efs-utils
``` 
![screely-1656479517089.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656479853280/hdknEnRIX.png align="left")
Optionally,  
[Install botocore](https://docs.aws.amazon.com/efs/latest/ug/install-botocore.html) so that you can use Amazon CloudWatch to monitor your file system's mount status.  
[Upgrade to the latest version of stunnel](https://docs.aws.amazon.com/efs/latest/ug/upgrading-stunnel.html) to enable encryption of data in transit.  
Continue,  
**Mount your file system using the EFS mount helper.**  
Make a directory "efs" (or any name) that will be the mount point 
```
sudo mkdir efs
``` 
Using the EFS mount helper command for each EFS file system that needs to be mounted and we can enable encryption of data in transit. Run mount command, 
```
sudo mount -t efs -o tls file-system-id efs/
Example 
sudo mount -t efs -o tls fs-abcd123456789ef0 efs/
``` 
And here, I have successfully mounted my EFS File Storage on EC2 Linux Machine.   EFS as our mount point. 
![screely-1656479528724.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1656480083596/YY6TVLWFw.png align="left")
Alternatively, We could have mounted NFS Storage using IP , 
```
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport 172.31.13.38:/ efs
```
Also, Mounting your Amazon EFS file system automatically can be configured by Updating the EC2's " /etc/fstab " file. More on that [ here](https://docs.aws.amazon.com/efs/latest/ug/mount-fs-auto-mount-onreboot.html),   
Open the /etc/fstab file in an editor. Add the following line to the file Note : relace with your ${file_system_id} and ${mount_point} :  
```
echo "${file_system_id}.efs.us-east-1.amazonaws.com:/ ${mount_point} nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport,_netdev 0 0" 
```  
Additionally,  If the EC2 instance and the file system you are mounting **are located in different AWS Regions**, see  
[Mounting Amazon EFS file systems from a different AWS Region](https://docs.aws.amazon.com/efs/latest/ug/mount-different-region.html) to edit the region property in the **"efs-utils.conf" ** file.  

AWS Doc Reffered : [Using EFS mount helper to mount EFS file systems](https://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-helper-ec2-linux.html)

Hope this step-by-step tutorial help in learning and getting you hands on experience for AWS Service - EFS and EC2.  

Thank you for reading and following along with the Blog.

Happy Learning.

Like and Follow for more Azure and AWS Content.

Regards,  
Jineshkumar Patel
