So let's get some practice with EFS.
And to do so, I'm going to go directly into the EFS console
and we are going to create our first file system
which is going to be a network file system.
I get prompted with a dialogue to go really quickly,
but as we want to learn the different options
when creating an EFS file system,
I'm going to go on click on Customize in the bottom.
So here are the file system settings.
So first, a name, which is optional
so I'll leave this empty.
Then we have to choose around availability and durability.
So we have a regional NFS EFS file system
if you want to have your data replicated across multiple AZ,
which is the default option, and this is definitely a setup
you need to have for production.
But if you're just testing EFS out
and you want to reduce cost,
you can opt to use a one zone type of EFS file system
in which the data is stored redundantly
only within a single AZ.
And so therefore if that AZ is down,
then your EFS file system is down,
and then you choose the AZ.
But to keep it simple, we'll keep it as regional next.
We have automated backup.
So we want to backup EFS file system
and you can enable it or disable it,
but let's just leave it enable right now.
Then we have lifecycle management.
So this is very important.
This is for cost savings
and is saying, "Okay, if my objects
are not being used very often,
then transition them into a different access tier
called the Standard-Infrequent Access Storage class."
And so we're saying, "Okay, if a file
has not been accessed for 30 days,
then transition it into IA,
which is going to save us some cost.
And then you can transition it out of IA
on first access or never as you want."
For performance mode, we can choose
within General Purpose and Max I/O.
So General Purpose, as the name indicates,
is for general purpose
and it's helpful when you have latency-sensitive use cases,
such as web serving environments
and content management system.
So if you have WordPress and you need some storage
then General Purpose will be great for you.
But if you choose the Max I/O option
is going to give you the highest amount of throughputs
and operations per second, which is great
if you have a big data type of use case,
but you're going to get a higher latency.
To keep it simple, we'll keep it as General Purpose.
Next for throughput mode, we have two options,
either the bursting or provisions.
So with bursting, we're going to get a throughput
that scales with the file system size.
So the bigger the file system,
the more scale we going to have plus some burst,
or for provision, you can say
a value between 1 and 1024 megabytes per second
of how much I want to be able to read my file system
which is a very helpful option
if you have a very tiny file system,
but somehow you need a lot of throughputs
right at the start.
We'll leave it as bursting.
We'll leave encryption of data at rest,
and we won't customize these settings.
Next, we have the network access settings
And they're very important, we have to choose a VPC
I'll choose the default VPC.
And then the mount targets
and because we've chosen a regional type of EFS file system
with three AZs available to us.
So each AZ is going to be assigned to a subnet.
I'll leave it as is, which is a default subnet.
The IP is automatic and we need to assign a security group.
And so we need to go ahead
and create a specific security group for my EFS file system.
So we'll go into the EC2 console
and then I will go into security groups.
I will create a security group
and I will call it sg-efs-demo.
And I will call this one EFS Demo SG.
For now, we will not have any inbound rules.
I click on Create security group.
And we cannot have this, so efs-demo is good enough.
Okay.
So my EFS demo is created successfully.
And to have it appear here,
what I need to do is to refresh the page.
So we'll start all over
but the settings are the basic ones, the default ones.
I click on Next.
And now I can remove these security groups
and choose the efs-demo security group
that I have created from before.
Okay, we're good.
So now we have done all the network access configuration.
I will click on Next.
We have a file system policy that is optional
and we will not touch it right now.
This is pretty advanced and we don't need it right now.
So I will click on Next.
And here we can review and create
all the file system settings.
So we're happy with that.
And when we're done, we'll just click on Create.
Now my file system is creating
and I will get back to you when it is created.
My file system is now available
and I can go in it and see that the fact
that there is six kilobytes of size
that is being used right now.
And when you have a EFS file system,
you only pay for the storage you use.
So right now, mark cost are zero.
So this is good. This is created.
And now we want to mount this onto EC2 instances.
Therefore, you know the next step,
we're going to create EC2 instances.
So let's launch some instance.
And I will name this one Instance A
because we will launch it in subnet of AZ A.
So we are going to run Amazon Linux, version 2.
We're good to go.
We'll use a t2.micro because it's free tier eligible.
We will disable the key pair.
We'll just use EC2 Instance Connect
to connect to our EC2 instance.
For network settings, I will leave it as is
and there will be a new security group created
with these rules right here.
So allow SSH access from anywhere, which is good.
Then we have eight gigabytes of gp2 storage,
but now, because we want to configure the storage
of the EC2 instance into Amazon EFS,
we can actually now do it from within the EC2 console,
which is very exciting.
So let me show you how to do it.
Before we had to run some commands.
So there are zero x File systems.
And you do Edit,
and it says that you cannot add a file system
before you choose to select a subnet.
So we scroll back up, we go to Network settings, we edit it.
And in subnet, I'm going to choose eu-west-1a.
So now that my subnet is created,
I can go back into file systems.
And as you can see, I can add an EFS or an FSx file system
so we'll add an EFS file system.
Then we'll click on Add shared file system.
It's going to be linked to my EFS right here.
The mount point is /mnt/efs/fs1.
This is good enough for us.
This is going to automatically create
and attach security groups for us, which is amazing.
And then it's automatically going
to mount shared file system
by attaching the required user data scripts.
So in the past, we had to run ourselves
onto these two instance manually
or create our own user data script,
but now this is done for us by the EC2 console
which is really nice.
Let's create one instance and launch it.
Okay, so this instance is launched.
I can go view all instances
and I'm going to launch a new one.
I will call this one Instance B.
We'll have Amazon Linux 2,
again, to make it quick.
I'm going to proceed without a key pair.
I will go into eu-west-1b.
I can just select the security group of launch-wizard-2
that was created just from before.
And then again, we need to edit this
and add a file system of type EFS.
And we'll use the same file system as before
and the same mount point
and we'll leave these options on as well.
So we're good.
Let's launch that instance.
And now, let's have a look at the interesting stuff
that has happened.
So I'm going to just do Instance state = running,
and refresh this until I see both of my instances.
So now they're both running.
And the interesting thing is that
if we go into the EFS console
and go to the network tab,
as we can see now each availability zone
now has multiple security groups.
So we have the efs-demo we created from before
but also the efs-sg-1 and efs-sg-2,
which were auto created by the EC2 console for us
and attached into our EFS file system.
So if I go into my EC2 instances
and then Security group right here,
I can look at, for example, this efs-sg-2.
Look at the inbound rules,
and as you see, it allows the protocol NFS on port 2049.
And the source of it,
if we have a look at the inbound rules himself,
the source of this is this security group.
And that security group is the one that is attached
into my EC2 instance Instance B.
So this allows my Instance B to access the EFS file system
because that security group right here called efs-sg-2
is attached into my EFS file system.
So all the setup is done by AWS for us, which is truly nice.
So now, if I go into one of these instance,
we're going to connect using EC2 Instance Connect
on this tab.
And then I will also do the exact same thing
by connecting to Instance B over EC2 Instance Connect.
So now I can, for example, verify the fact that,
yes, in ls /mnt/efs/fs1/,
there is an EFS file system,
and now we need to create files in it.
So to make it simple, I will elevate my right
and type sudo su.
And then I can do echo hello world
into the /mnt/efs/fs1/
as a hello.txt.
So we've created that file, and then the hello.txt.
And if I do cat and then this entire file name right here,
as you can see, it says, "hello world".
So this file has been created into my EFS file system
from this EC2 instance, which is an eu-west-1a.
But now if I go into my second EC2 instance
and do ls and then the same file system,
so I look for files in it,
as you can see, we also see this hello.txt file in it.
And if I do cat and then cat the file hello.txt.
It says, "hello world" as well.
So, as you can see, the EFS file system
is indeed mounted as a network drive
onto both my EC2 instances
and they are in different AZs and they share the same EFS.
So that's amazing.
And that's a different kind of storage
that you had the demo of it right now.
So that's it for the EFS demo.
That was pretty complete.
Now to just clean it up,
what you can do is you can terminate
these two EC2 instances.
So you go here and you terminate them.
And something else you can do
is you can go into the EFS file system.
You can delete it by entering the file system ID.
And then when everything is deleted,
you can go ahead into your security groups
and delete the extra security groups
that have been created during this demo.
Okay, that's it for this lecture.
I hope you liked it.
And I will see you in the next lecture.