Instructor: All right, so in this lecture,
we are going to learn how to use EFS.
And, for this, we first have to go
and create a Security Group,
so we'll go to the Security Group side.
We'll create one and I'll call it My EFS Demo
and it's just a security group for EFS,
just so we can understand exactly how
security groups work for EFS.
So for now, inbound, I will have no rules
and outbound, I will have all the rules, as well.
So, this is just a default security group, here we go.
So now, My EFS Demo, right here, is being created.
Next, I'm going to go to Services,
type in EFS, and open up the EFS File System.
As we can see, this is a file storage
to use for our EC2 Instances, just like I told you, huh?
(he laughs)
Next, we create the file system.
And, we have three steps,
the first one is to configure it,
the second one is optional settings
and the third one is to review and create.
So, we're going to create this in our default VPC.
And, as I told you, EFS is accessible across
3AZ, so we have eu-west-1a, 1b and 1c all ticked
and they're all going to be created
within their own subnets.
They will get assigned an automatic IP address
and then I have to assign a security group.
Now, we're going to remove all the default security group
and I'll just type in the EFS Demo security group.
So I'll assign this EFS Demo security group
to the three subnets and, here we go.
We're done.
So this is basically saying that our Elastic File System
has a security group attached to it
and this is how we could control
which Instances can talk to it or not.
Now let's go to Next Step.
We could Add Tags if we wanted to,
so I'll just call it EFS Demo as a name, that sounds good.
Here we can choose the performance mode, so as I told you,
there is General Purpose or Max I/O.
But Max I/O is when you have thousands
or hundreds of EC2 instances.
So we'll just use GP for now.
The Throughput mode we can choose Bursting or Provisioned.
We'll just use Bursting, it's the simplest one,
but Provisioned will be have to specify
how many megabytes per second we want.
And so for the exam, just know that Bursting is enough.
And Enable Encryption if we wanted to enable
the encryption at rest in which we would choose
a KMS master key, for example, aws/elasticfilesystem
to encrypt our data at rest.
For now, I'll just disable it,
it'll make everything more simple.
Click on Next Step and we Review everything.
It all looks good and click on Create File System.
Now this can go and take a little bit of time to happen
because this will actually provision a file system
and assign an IP for you.
So, now the system is created,
but as you can see in the bottom,
the Mount Target State is in creating stage.
You can also see that, for now,
we're going to get a File System ID
that we'll use later on in this course.
We get a Metered Size so we get actually the number of,
the size of all the files we put on our file system
and the number of Mount Targets, so how many AZs it's on.
So this looks good.
Now we get to have to wait, but in the meantime,
I'm going to go ahead and create an EC2 Management Console.
So, let's go to my EC2 Instances
and I'm going to launch Instances.
I'm going to launch in Amazon Linux 2
and I'm going to say okay to t2.micro.
Then I'm going to Configure Instance Details
and I'll say this one, I want it to be in eu-west-1a.
Sounds good to me.
Then I'll click on Next Add Storage,
Next Add Tags, Next Configure Security Group
and I'll just create a new security group.
I'll call it ec2-for-efs,
just because I want to show you that we can have
a security group dedicated to these EC2 Instances.
I'll allow SSH on Port 22 so I can install stuff on it.
Review and Launch, then Launch
and say I'll use my key pair AWSCourse.
Launch Instances and I will basically
launch a very similar Instance.
So I right click and Launch More Like This
and I'm going to edit basically the AZ I'm in.
So in Instance Details I'm going to edit
the Instance Details and say okay,
what I want to do is now to launch in eu-west-1b,
in my subnet eu-west-1b.
Sounds good, click on Next Add Storage, Next Add Tags.
Security Group we're going to reuse
that ec2-for-efs security group.
So that's perfect, ec2-for-efs, yeah, perfect
and click on Review and Launch and Launch.
I have the key pair and okay.
So now what we get out of this is
that we have two instances, two t2.micro,
running in eu-west-1a,
eu-west-1b and they're all going to have
this ec2-for-efs security group
and we're going to configure EFS on both of them.
So what I'm going to do is get the Public IP
and SSH into these Instances.
So here I can SSH in my first Instance.
Okay, here we go.
And my second Instance is right here.
I'll also get the Public IP
and I will run the SSH command on this one.
All right, so I'm in my two Instances.
They have different Public IP, different Private IP.
They're in different Availability Zones
and now I have to Configure EFS.
So for this, we can go to Elastic File System
and you can get basically Mount instructions
from a local VPC.
So you can click on it and here it shows you exactly
how to setup your Instances.
So the first thing I have to do is to run sudo yum install
and then the amazon-efs-utls.
It's basically to help us mount the EFS.
So I'll just do this and install it on both machines.
So it's going to install it.
Perfect, it's done.
And then, you have to Mount your File System.
So we'll create an EFS Directory on our Instance.
So we'll go in Create an EFS Directory.
I'll create actually a slash, a root at EFS, so /efs.
So here we go, sudo mkdir.
I'll do it here too, sudo mkdir /efs.
So now if we go here, we can see
that we have an EFS Directory that has been created.
And the next thing we have to do
is to Mount using the Helper.
So, as you can see, we can use TLS Mount option
if you wanted to use encryption to talk to EFS,
for now we're fine.
And so we'll use this command right here, sudo mount -t efs
and here is the File System ID.
So we have to use that.
So let's try it out.
And we have to get the File System ID,
so let's go back to EFS.
Oh, this is the right File System ID because we are in EFS.
As you can see it's gone from here.
So let's go back to the mounting instructions
and we're going to run this command
and let's see what happens.
So we are going to run it
and make sure you add slash before the EFS.
Press Enter and right now, not much is happening.
So let's go back to our, here
and as you can see though, my Mount Target is available.
But so the problem is this looks like a timeout,
and why is it timing out?
Well if you do remember, we have security groups attached,
My EFS Demo and right now,
they don't allow it any inbound connection.
So we need to allow the security group
to get inbound connections from our EC2 Instance.
So I'm going to go back to my Security Groups
and I'm going to find my EFS Demo
and Inbound Rules I'm going to add a Rule,
and you can actually add any ports really,
but I'll just add the NFS port.
And I'll say the source is going to be
the ec2-for-efs Security Group
and I'll say allow traffic from my EC2 instances.
Allow NFS traffic.
So the idea is that now we're saying,
okay these Instances who belong to that Group
will be able to talk to my EFS Network File System
on Port 2049.
So let's click on Save and now this row has been added
and that should help out.
So now, let's wait and do a sudo mount
and now it succeeded.
So now the EFS File System is mounted
so I can Copy this entire command
and Paste it right here on the other one
and now it worked as well.
And so our EFS File System has been mounted.
Now, how do we verify that it worked?
Well, how about we go to the EFS Directory
and here I'll use the sudo user just to make things simple.
So I'll go to the EFS Directory and use the sudo user
and here I'm just going to say
echo "hello" > hello.txt file.
So if I look at it, now I have a hello.txt file
that contains the word hello.
And this is in AZ eu-west-1a
and now let's look at this.
We'll do LS and we find the exact same hello.txt file,
even though this E2 Instance is eu-west-1b.
So I'll cat hello.text and we find the exact same content.
So the cool thing is that now, both these Instances
into two different AZ have access to the EFS Volume Drive
and they can just have the same files
mounted on the same endpoint.
So that's really, really cool
because we have effectively mounted an NFS drive.
And so the really cool thing you need to see here
is that we had to troubleshoot a timeout connection
using Security Groups and that is something
that can be asked of you at the exam.
But overall, pretty easy to see how things work.
I think it is quite natural
and I like the way that you can get your Mount instructions
very clear on this little popup.
So, yes, that's it.
You just need to know how to do these things,
but it's pretty easy and now you're an EFS expert.
(he laughs)
That's it, all right I will see you in the next lecture.