In this video, we're gonna learn about Cloud computing's most valuable
resource elastic cloud computing.
Elastic cloud computing or commonly known as ec2 is
a cloud component that provides scalable virtual
servers on demand.
There are many different os's like Linux Mac and
windows. You can choose from to run in your ec2 instance.
Another powerful feature of ec2 is you
can pick it choose different memory storage and CPU configuration
for your virtual instance.
Prices and Hardware will vary depending on whichever you
choose.
Ec2 can either be built as on-demand pricing
or you could pay ahead of time for a significant discount in
the reserved model.
To better understand your lab environment. You will need to
learn where to find ec2 instances inside AWS console
and explore some of its attributes.
After that, you open up our final terraform file
to piece together the resource in the code needed
to create one. Okay, let's get started. All right,
here. We are back in our web browser
again inside the AWS console.
Since we're gonna be talking about ec2, we don't need to go to
VPC any longer, but the same Rule still
apply. We'll go up here. We're going to search for ec2.
And it should be our top result here as you can see. I'll click
on ec2.
And here we go. So just like the other
resources you saw earlier. Here's our main ec2 page
and all the drill Downs
that it provides. There's obviously quite
a few attribute our few components
that are inside the ec2 umbrella here. We're only gonna
talk about ec2 instances for right now as a that's just
what this course is laid out for but I encourage you to
learn more first thing you should notice is that this is only showing
us ec2 instances and ec2 other components
running in the US West 2 region
as this is the one that we're going to use for our demo. You can
see here that's up here on my cursor is an organ
this highlighted. That means we're in us with two
If by any chance that you had ec2 instances is
running in different regions, you would use this ec2 global
view right here, which would bring you to a
global view to show you all your ec2 runs in ec2 instances running
across the world down the left-hand. We have
a lot more components like I was saying to do
it easy to but we're gonna skip all those we're
gonna just focus on instances and so over here
on the left. We're gonna say instances, although probably really
quick to talk about right here is you have instances running in
instances. The difference between these two is these are
actually running and you can interact with them. These are
instances you have but that may be in a stopped State. All
right, perfect. So let's click over here on instances.
Okay. So here's all the actual instances that
would be for this region for Usos
2 as you can see, there's none here and at the
top you can see that there is these headers into the
state instance type status check alarm status. Those will
come a little bit more familiar with you once you we spend
one up and see.
Down here because we don't have any instances you
can see down here in the details pain that is not here. There's
nothing to go on the normal resource
configuration up here. You have launch instance, which
is a wizard which I am gonna show you this one because
I think it's important to map this to what we see in the terraform file.
You see the actions button here,
which if we want to like modify or delete an instance
and then this instant State drop down right
here, it allows you to stop start reboot hibernate or
terminated instance. Of course, if you have one to click
on since we have none, they're all grayed out.
All right. So let's go ahead we're gonna click over here this launch instance wizard.
Okay. So here we are and this is
the aws's ec2 wizard. We'll launch
in instance and here the first thing you should notice is the name
and tags little card here. And this is just like we
saw on the terraform file the tag with the name and the
value. So here you would put whatever you
wanted. This next card here is they want to
know the OS images here. It just automatically highlights
Amazon Linux and you have it
right here, which you have the kernel the type
64-bit architecture on x86. That's
the actually one we're gonna use in our in our
lab as well. But here just automatically picks it for you, but you
could pick a bun to Red Hat Mac OS Windows, whichever
one you wanted to do.
Next card we go through is instance type.
So this is the type of machine that you want to spin up and
this is the CPU memory configurations. I was
talking about because we're gonna stick with the free tier. So
it doesn't cost you any money. We are gonna stick with the t2 micro
which is the free tier eligible. Like it says right here and the
t2 has one virtual CPU and one gig of
memory, which is plenty for us for our
purposes here for this lab. The next card down
is key pair.
So when you spin up a Linux ec2 instance,
you need to be able to access it in one
way.
You can access it is over SSH and is that that's the exact way
that we're gonna access it as well.
Amazon would rather and the industry
would rather you access these Linux servers
using an SSH key pair of just user password.
So what it's asking for here is saying hey, do you already have a
key pair? You can use or we can create a new one by this little
designation here. And this will make more sense when we look at
the terraform file and we're gonna use our own key pair.
So when we spin it up, we'll be able
to ssh in so here in this network settings card. So
some of this information should look familiar to you here. It's
picking our VPC. Now, this is the default VPC not
our lab one that we're gonna create because it's
the only one that it can pick if there was multiple ones you
could edit here and select the different one. The subnet
is just there's no preference. This is gonna pick a random one
in our lab. We are going to actually assign one here.
We see the auto assign public IP, which you should
look familiar to you. It's enabled here we get to security groups.
And if you didn't have a security group, you could
create one on the Fly here instead of having to go to the
security group AWS Resource page and then back here.
Or you can select from existing one and so
obviously we're gonna create our own Security Group and we're gonna sign
that to the ec2 instance.
Next you can see the last part here is configure storage
and what for the free tier basically you
can get up to 30 gigabytes of
free tier right now.
And as you can see here the default that
it picked for us was an eight gig root hard drive with using
gp2 and gp2 is basically the type
of volume it is and when that comes
down to is how fast is this disc gonna be for us and so all
these defaults are fine. And if we were
to ready to go we would click launch instance and
then within a few seconds within I think it's about
30 seconds. You would have a running Lennox Amazon
Linux instance that you could interact with. So I'm gonna
click cancel here because we're obviously we're not gonna do the wizard, but I
just wanted you to see all the the values in
the attributes needed to actually spin up
an ec2 instant. All right, so I'm gonna stop here
with ec2 instances because there's a lot
more going on here and it's definitely Beyond this course,
but I wanted to get an overview of what the main
page look like and and The Wizard if you
ever needed to do it through the UI, so from here, let's go
ahead and jump over into the terminal and then let's look at the ec2 Terra.
file
Alright, so here we are back in the terminal and I'm
going to open up our ec2.tf file
here.
Here we are back on Terminal again. I'm going to open up our ec2.tf
file.
Okay, so as we saw in the last
video this resource has got
a lot going on because as you saw through the wizard and the AWS
console is quite a few things. We need to to fill
out to be able to spin up an ec2 instance. Now
some of these are defaults and I didn't need to include them but I
did it for explicitness. So you have an
understanding of what you can and cannot manipulate. And in
fact, there's even more options here even in
the eight of us console. There's an advanced section down below that I
didn't go into but there's more things you can change but let's
go over this and let's talk about
It just looks like so here we are.
Same thing. Hopefully you're becoming familiar.
When you're seeing this now. We have the resource declaration. We're gonna use
the instance terraform AWS provider
Library here. We're gonna name this resource lab
1 and that's important and I'll show you in a minute
why it is
Line two here. We're picking the Ami, which is just
the machine instance and what the
what this does is just says, hey we want to use this version
of Linux or we want to use this version of mac. And this
is what we're gonna spin up in in the instance and here
we're using a variable we're using the VAR dot
Ami syntax sugar here and for the
terraform and that's because that's because we've hard coded the Amazon
Linux Ami in another file called vars
and I'm actually gonna we're gonna look at that as we
go through this too since we haven't covered it before.
I'm gonna pick the instance type here which we talked about in the
80 was console is going to be the t2 micro.
Here we're picking our subnet. And if you remember from the subnet
video, we called our subnet sub lab subnet
public one and here is exactly pulling that
out. It's saying hey, we named that resource not
the actual name of the subnet. But the name of the resource.
Is this lab subnet public
one?
Here you can we can apply a list
or an array of Security Group
IDs for the VPC since we've only created One Security
Group, which was the allow SSH HTTP or
putting that in here and we're using the string interpolation the
dollar sign Curly's like we saw in the past videos.
So this is the one that went out
we on the AWS console online 12 here, which is key name.
This is the one we saw with a key pair and this is where we have
an option to upload our own SSH
key pair to the ec2 EC
to Amazon and the ec2 instance so we can SSH into
it and how this works it basically only
uploads the public key. We
keep the private and uploads the public key in
that public key will be put inside that amet that ec2 instance
when it's launched and that's how we'll be on be
able to authenticate ourselves to that instance. And so
this key keyname right here is mapping to
the resource online starting online 33, which will
cover in a second here.
Here we're setting the availability Zone. And basically we've
hard coded you. I've hard coded Us West 2A
into a variable into the vars file and I'll show
you that in a second.
This should be looked from a
little familiar as well. We're associating a public IP address to true
on this because we want this ec2 instance when it comes
up to actually have a public IP address.
On line 20. This is the root block device. So this is the
root device. And if you remember from the AWS console part, we
were looking at it had the it allows you
to pick the size of the root part the root device and
The type which was the gp2. So here this is
all optional. It would have already picked the eight gig
the gp2 by default. But because I wanted
to show a little bit more here. I went ahead and
from lines 20 to 25 to show you that you can
set up your own root volume different sizes different
speeds and the biggest part here
is line 21, which is the delete on termination this means
whenever we destroy the ec2 instance,
we create it'll actually make sure that there's no
root device left around as well and obviously
because that could cost money and for security reasons
So here we get them down to our tags lines 27 through
30. And this time we did a little something a little different on line
28. You see the normal name tag, which is lab one,
which is what we're gonna call this ec2 instance. But I've added
this other tag here called environment and we were just
set it as lab and the reason why I wanted to do this is show you
is that if you had a bunch of development servers or
a bunch of staging or Production Service, you could add
a different tag for them. So you could group them together for easy
searching or if you wanted to apply some different rules. You
could apply them to all with this tag. That's obviously a
little bit more advanced, but I wanted to show you that instead of
keep showing you the name tag over and over. I wanted to show you something a little bit different.
Okay. So let's go to line 33 here. And this is where
we're actually creating the key pair and we're using
the same resource and we're using the AWS key pair library
from the AWS provider and terraform
and we're naming this resource lab region
key pair and if you look right there online 33 we
call this resource labradget key pair. If you
come up back up to line 12 again, you can see that where
are we are referencing the
we're referencing the resource name up there and that's
how it knows where to find it.
So we'll go down here line 34 just the
key Name Lab region key pair and then here we're
using this terraform built-in function called file and
it's just basically gonna take in a local file on
path and it is that's what's going to be uploaded. I
will show you the variable where this is the varda public
keypath later the name of this is hardcoded because
I've I've included a script for you to run
that'll actually create the keep here for use and it'll actually name the
key pair or something. So you do not have to worry about
the names it all just match up to work for you.
Now here's something we haven't done before and I
wanted to add this and I'll show you why because it's gonna make it lives a
little easier at the end. This is output. So it's not a resource but
an output and so with this basically says is that terraform is
gonna spit something out to the terminal when it's done
and what we're trying to do here. We're getting the
lab one ec2 instance. We're gonna
reach in and get the public IP. Once that server is
up and running the virtual instance up and running. We're gonna get the virtual IP
here. I mean the public IP here and then we're gonna
put that out to screen. That'll just make it nice little it'll make it easy for
you when it's time to SSH and do it. You'll have it on the screen. You don't have to go searching
through the AWS console to find it. Okay.
So there is our ec2tf
file but what I wanted to show you
I'm gonna put it side by side here. Is this variables file?
And so it's just in a file called vars that TF. There's
nothing special about this file. You could have added them to any of
these other files, but I like say I like separation. So it's a little
bit easier to explain
And if you look over here on this left column, you can see that all
these are just variables that we're using through
all the terraform files and the one variable is
called AWS region and it's set to Usos 2. You
have another variable called a z which is defaults to
us West 2A and then here is that keypath. So
on the right column, you can see on
line 34 on there on
the right column key name you can see that I'm sorry
on line 35 where it says public key and it says VAR Dot
Public keypath
It's basically getting this right here and then inserting
the name here. It's looking for
that file on disk local in this
case of lab key pair and that does get when I told
you we created with that the bash grip that will get created and
that will be there. So we need to create them before we
run terraform, but we'll do that in the next video. And then here's
the Ami which we were talking about the machine
image.
And this ID right here, I just went to
Amazon search for images and found the Amazon Linux
2 image Ami for you in Usos 2,
and I just picked that one nothing special there,
but it allows us to use this now.
The variables make a little easier for separation
concerns. Also, if I need to change something instead of
having to change an ID or an Ami somewhere
in a bunch of different files. I have to change it one place because
terraform will compile all this for us.
All right, let's close that file.
Go ahead and get out of here, too. We're done in looking
at the terraform file. And so let's
head back over and let's recap what we've done so far.
Okay. So what we learned about so far in this video, we've learned
about ec2 and some of its features like you
could configure memory and CPU options in different
instance types you explored ec2's interface
inside AWS console and got a
glimpse at some of the metadata needed to create one. Finally you
open the terraform file that would create a Linux server
for the lab. You also got to learn a little bit about using
a vars file to make things a little bit nice and neat.
In the next video You're gonna put all
this knowledge together and you're finally gonna create your
lab.
See you soon.