Before demo lets first discuss why another storage solution when we already have S3 i.e Simple Storage Service and EBS i.e Elastic Block Store.
What EFS i.e Elastic File System brings on to the table which S3 and EBS are not able to provide ?
We are going to limit this post with how much easy we can use a storage solution for a particular task and storage use case.
S3 – Simple Storage Service, is a block storage works best for any kind of storage need integrates well with cloud front. Can be accessed from anywhere on the internet, depending upon the permission set for the object as well as bucket. As its object store S3 does not supports installation of Operating System. Works good for static contents or hosting websites.
EBS – Elastic Block Store, is like a hard drive attached to your PC. So when you want performance and fast IO operation we should use EBS. It’s a block storage and OS can be installed on to it. As Performance and Fast IO is biggest USP of EBS, EBS volumes are localised in a particular availability zone in an AWS region. This should make sense as we would not want to connect to a network drive which is 1000KM apart from the host EC2 instance.
EFS – Elastic File System, let’s say you want to share data across 100’s of EC2 instances and that is dynamic as well and we require performance as well as IOPS should be equivalent to EBS volume IOPS.
This is where EFS comes in to play as EBS is limited to particular AZ, yes we can take snapshot then transfer it to different AZ and boot up the EBS volume there but its a pain taking task provided if we want this to be done 100 times in a day.
EFS is a network file system works on NFS 4.1 spans across all the AZ’s in an AWS Region. Can connect to 1000’s of EC2 instance at a time. Provides GP2 as well as IO Provisioned storage options. But yes It’s costly as well – use it wisely.
We will spin up 2 EC2 instances in two different AZ’s then Will create EFS instance. Post that we will mount EFS to EC2 instances. Then we will see file sharing in action.
Step 1 – Start 2 or more EC2 instances in different AZ’s
While creating EC2 instances make sure to ADD NFS rule in the Security Group.
Here we are allowing NFS from anywhere, you can restrict it to particular SG from EFS also.
Have launched two EC2 instance in two AZ’s of N-Virginia region
Step 2 – Setup EFS
We would find EFS under storage option on AWS Console
Page would look something like this – if this is first time you are using EFS.
Click on create file system. Below screen will popup.
Here, EFS is being provisioned for all the AWS availability zone in N. Virginia. A SG is also being created for EFS if we want to restrict we can create our own SG and assign it.
Clicking Next will take you to configuration settings of EFS, which will looks something like this.
We can hit next here as default settings suffice the demo purpose, but for the geeky and curious mind let’s cover the enlisted options on configuration page.
Life Cycle Police – as told earlier EFS is costly and is charged for storage used. So we can set life cycle policy where is we are not using certain files they will be moved to EFS-IA i.e EFS- Infrequent Access which is cheaper then Standard EFS storage class.
Throughput Mode – this is similar to EBS burst credits, in burst mode – EFS throughput will scale based on the EFS size grows. So there will less chance of wastage. With Provisioned Mode we can specify how much throughput we require out of the box and EFS will be provisioned with the desired setting.
What is throughput ?
Here Throughput means the amount of MB’s which we can read or write to be EFS file system.
Choose Performance Mode – This relates to IO operations, General purpose will suffice most of the needs. Max IO can be used for the scenarios where we are aware that there will be 1000’s of EC2 or other parallel connections to the EFS.
Enable Encryption – EFS integrates with AWS KMS which can be used to encrypt data at rest.
phew … that was hell lot of details let’s move forward with the demo !
Click Next, you will see some thing like below.
I have only provisioned EFS for AZ’s where I have EC2 instance, you create all the AZ’s thats not a problem – for the demo it will suffice.
Click Create File System, you will see something like this.
Refresh after some time – status would change to Available.
Step 3 – Login to EC2 instances and Mount the EFS.
It’s time to SSH both the EC2 instances and see EFS in action.
// install utils for efs - for amazon ami $ sudo yum install -y amazon-efs-utils
// create a directory for mount point $ sudo mkdir /efs
// mount the efs to mount point - fs-c4d1dc45 - is the efs id provisioned $ sudo mount -t efs fs-c4d1dc45:/ /efs
Step 3 – See EFS in action
Move to /efs directory and ls into it, off course you will not see anything there.
Let’s create a file and try reading it from the other EC2 instance.
Here we can see, have created file from one EC2 instance and its being accessed from other EC2 instance.
That’s all Folks!
How to install AWS EFS Mount Helper?
The EFS mount helper is part of the amazon-efs-utils package. The amazon-efs-utils package is an open-source collection of Amazon EFS tools. # For Centos & RHEL $ sudo yum install -y amazon-efs-utils # For Ubuntu $ sudo apt-get update $ sudo apt-get -y install git binutils $ git clone https://github.com/aws/efs-utils $ cd efs-utils $ ./build-deb.sh $ sudo apt-get -y install ./build/amazon-efs-utils*deb
How to install NFS Client in Linux?
$ sudo apt update $ sudo apt install nfs-common $ cd / $ mkdir efs $ sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-029352aac72025ee5.efs.ap-south-1.amazonaws.com:/ efs
- Jenkins Tutorial: Install Jenkins on Ubuntu - November 27, 2022
- AWS Tutorials: EFS Demo – Working with EFS with EC2 instance - October 3, 2022
- Minikube – Addons - March 22, 2020