Welcome to the session.
In this session, we are going to see elastic filesystem, it's one very easy to use service, but also
very, very powerful.
If you need a shared storage on AWS, then I think you can go with EFS.
You can mount EFS filesystem on any directory in your operating system, and as AWS says, it's
scalable, elastic, cloud nativ and you also get the price over here, which I find is really very cheap.
So if you have a cluster of servers and they want to store data at one centralized place, you can go
with EFS, you can mount it just like you mount an SBS partition.
But EBS is only for one instance at a time. EFS
you can mount for multiple instances.
And that's why it's called a shared file system.
You can check this link, there is a very nice video created by AWS about what is EFS.
I recommend you really watch this one.
Let's scroll down and see the use cases.
So you can use it for your containers and your serverless applications, you can use it in analytics
and machine learning to store your data if you're serving Web services and content management like a
dynamic application dynamic website, lets say you have a cluster of Web server and users are uploading
images.
You can store all the images centralized into EFS from your EC2 instance, also your social media.
Even for storing your database back up, you need a centralized place where you can throw all your database
backups.
So I'm going to use the wavecafe instance and all the images of my Web service, I will be storing
it in EFS.
So let me log into this instance.
So we are in, Lets do sudo -i
I will go to /var/www/html, so here we will take the case of this images dir, we
will mounted on EFS Filesystem.
So then all the images will be stored in EFS filesystem, and if it's a dynamic application, this will
be very useful.
When you have a cluster, when you have multiples of ec2 instance, and they will be also storing images
in the same dir.
So the images data will be in sync on all the servers in the cluster.
So let's go to service.
So, again, you can read about it over here in this page, EFS is a network based or a shared
filesystem over the network, and it will be inside a security group.
So we better create a security group before we create the elastic filesystem.
So let's go to security groups.
We will create a security group, will name it as.
efs-wave
-image
And it's NFS based, so we are going to select an inbound rule NFS service.
And we'll say it will be allowed from the security group of our Web server.
OK, so any instance in this security group can access my EFS on port 2049 NFS port.
Let's create the security group, the description, let's give the description.
And let's create a security group.
OK, now let's go back to EFS and secret file system.
Let's give a name wave-web-image.
I click on Customize.
So I see a lot of options, performance mode.
You have a general purpose and Maxe I/O, keep it general-purpose.
If you go Max IO, there will be charges, throughput mode, mode, bursting, provisioned is for high performance.
It will be encrypted if you don't want, you can uncheck that and then let's go next.
In the network, so it will be in the VPC.
And as I said, we understand VPC later, we will keep it as it is. Security group.
We are going to change.
We are going to select.
Our security group that we have already created.
And remove the default security group.
I will do it for all the availability zones.
Make sure you do this, otherwise you will not be able to mount your EFS filesystem.
If you selected all that, click on next.
And then go next, select everything default, filesystem policy, say create.
So EFS filesystem is created, you can think of this same like we have created an EBS volume,
but this will be shared one. And to access this there are different ways you can access it or authenticate
to it by using IAM user also.
But we're going to do it through access points.
Click on access points there.
And to create access point.
Select your file system, that is the file system that we have created, so we are saying the access
point is for this file system.
And scroll down and say create access point.
And the access point is created now let's see how we are going to mount it to our to our ec2 instance. So you
can access this documentation by doing a simple Google mounting EFS filesystem.
You should find the documentation or you can use this link directly.
First, you need to install Amazon, EFS utils, so click on this link.
So you can mount it, Aah sorry, you can install this on Amazon, Linux, which will be very easy if you're using
Amazon, Linux, you can just say yum, install amazon,-efs-utils, but if you're using any other
operating system.
Then you have to install efs through a different way, you have to install it, like if you're using
CentOS or Ubuntu or any other Linux flavor, then you install git, you clone the source code and you
get into that source code and you say, you install a make package, install rpm build package and
you run this command, make rpm. This will create an rpm and then you can install that rpm by using
this command and that's how UTILS will be installed.
If you're wondering what this is, think of this as the driver to access your efs.
Filesystem.
If you're using Amazon, Linux, like I'm using, then you can just say, yum, install, this command
.
Or if you're using any other Linux flavor, then there is a whole process for Debian, for Ubuntu machine,
this different process.
Check that.
It's going to you have to execute the script in the source code and then you have to use apt command
to install Debian package.
So if you're using Ubuntu or Centos or Amazon, in any case, you have to install this package.
So I'm going to copy this one.
And enter it in my ec2 instance.
So it has installed the amazon efs utils, the driver to access my efs filesystem.
Next, we'll see how to mount it, so going back to a documentation, mounting with efs Mount Helper or
mounting your Amazon efforts filesystem automatically.
Let's click on that.
So the best way is you put it in the fstab file, the entries and it will mount it when it reboots
automatically.
So if you scroll down slowly, you will see the mount option, so if you're using IAM, then you can
go with this.
If you're using EFS access point like we are doing, we are using access point, then you have to use
this.
So let's copy this and let's bring it in our notepad.
So I pasted here in my notepad, I'm going to paste it one more time.
So first you give this in the fstab file, you give this entry filesystem ID, efs mount point where you
want to mount. Type efs.
And instead of defaults options, you have to give all these options and 00 for fsck & dump, so let's make changes.
Let's get our filesystem ID.
So I go back to efs filesystem.
And there is my filesystem ID.
So I'm going to copy that.
And put it in my notepad, filesystem ID there, OK, then you have to give the access point access
point equal to the access point ID.
So let's get the access point, let's go to Access Point, and that's our access point and that's our
ID.
Let's copy that.
Actually, here you get the filesystem ID also.
Let's put our access point out there.
And that's our entry for fstab.
Let's copy all this.
And let's go to our instance. Now before I do any mount I'm going to take back up of this images dir
dir
I'm going to copy these images or move everything from these image is directory.
Oh Wait, let me create directories somewhere, mkdir /tmp/img-backup.
And then I will move everything from the images dir to dump.
Image backup.
OK, I should not see anything now here.
OK, now let's open the fstab.
And let's copy all this.
OK, last thing we have to update is where we are going to mount it, so we have to give the complete
path. EFS mountpoint /var/www/html/img
.
Check it once again, if you're good, then save and quit.
Time to test it, mount. -fav, run this option.
And you should see successfully mounted, if you're seeing some error, its timing out, check the security
group of your EFS, whether it's allowing access from your Web server.
And also check that you're doing it on that I dir.
Check the typographical error for your filesystem with your access point, and if everything is correct,
you should be able to mount it successfully.
Now, let's bring back our data from /tmp/img-backup to images directory
It's back, we can check in df -h command.
It's mounted and now any data I put in this directory is going to my EFS filesystem.
This is very good in a cluster.
We need shared storage so many times, and this is, I find, the best way on AWS to use,
EFS filesystem.
And if you're good with this, I recommend you create its AMI, which we are going to use in the auto
scaling group session, so I will go to Ec2.
Instances.
And I'll create its AMI, Instance State, Action.
Image, create image, I will name it, as wave-web-img-efs. That this is with the efs
filesystem
And say create image.
So AMI is in pending, state, I have the previous AMI and I'm going to remove that, I will say deregister.
And I'll go to snapshot.
And make sure you're deleting the right snapshot, anyways it will not allow you to delete a snapshot if
it's already connected to the AMI.
And I've deleted that and the new AMI is getting created and that will create another snapshot.
The AMI is ready now you can delete your instance.
You really don't need to delete EFS File, EFS 5 gb free for 12 months, it comes in your free tier
and we anyways need it for the next session in autosaling group.
So once you're done with this, create AMI, terminate the instance and join me in the next video.