Welcome, so in this lecture,
we are going to launch our first E2 instance
running Amazon Linux.
So for this, we'll be launching our first EC2 instance
which is, well, a visual server,
and we'll use the console for this.
We'll get a high level approach
to all the various parameters you have
when launching an EC2 instance,
and you'll see there are many,
but we'll learn the most important ones.
And then we will launch a web server
directly on the EC2 instance.
Using a piece of code, we will pass to the EC2 instance.
That is called the user data.
Finally, we'll learn how to start,
stop, and terminate our instance.
So let's get started and launch our first EC2 instance.
For this, I'm gonna go into the EC2 console,
then I will click on instances
and then click on launch instances.
So in there, I'm able to launch my first EC2 instance,
and to do so, I need to add a name and tags.
So the name is going to be My First Instance
and that is the name tag,
and if you wanted to add additional tags
to tag your instance differently,
then you could click there,
but you don't need to click on this.
Using just name as My First Instance is good enough.
Next, you need to choose a base image
for your EC2 instance.
This is the operating system of your instance.
As you can see,
there's a full catalog that you can search from,
but we're going to use the ones from the quick start
that are very, very helpful.
And the one we'll be using is the Amazon Linux,
which is provided by AWS.
So in it, I will choose the Amazon Linux 2 AMI.
And as you can see, that one is free tier eligible,
so we'll just leave it as is.
So this gives me Amazon Linux 2,
and the architecture I will choose is 64 bit x86.
So everything left pretty much as the defaults.
And we'll see in this section,
and moreover in the other ones,
that you can create your own AMIs
and you can found them in here.
Okay, but currently, we're just going to use the ones
provided by AWS as quick start.
Next, we need to choose an instant type.
And so instant types are going to differ
based on the number of CPUs they have,
the amount of memory they have, and how much they cost.
As you can see right now, I have a T2 micro selected.
This one is free tier eligible,
so it will be free to launch one of them
during an entire month if we leave it running,
so this is what we'll be using.
But in here, you could scroll down
and look at other types of instances.
For example, T1 micro is also free tier eligible,
but that's older generation.
And as you can see, you have a bunch of instances
right here available to you.
Some of them are going to be free tier eligible,
some of them will not, and by default,
the one that's gonna be free tier eligible is a T2 micro,
so we'll be using that one a lot.
If you wanted to compare the instance types,
you will just click on that link,
and it shows you all the type of instances in here
as well as how much memory they have and so on.
So right now, we'll be using a T2 micro.
Okay.
Next, a key pair to log into your instance.
So this is necessary
if we use the SSH utility to access our instance,
and we will be using the SSH utility in this course,
therefore it is required for us to create a key pair.
So as we can see right now, there is no key pair,
and we could proceed without a key pair,
but for now we won't do this.
So let's go ahead and create a new key pair.
And the name is going to be EC2 Tutorial.
Then you need to choose a key pair type,
so we'll be using the RSA encrypted.
Okay, this is good.
And then the key pair formats.
So, if you have Mac or Linux or Windows 10,
then you can use the .pem format.
If you have Windows less than version 10,
for example, Windows 7 or Windows 8,
then you can do a little shortcut and directly use a PPK
which is going to be used for PuTTY,
and PuTTY is how you do SSH on Windows 7 and Windows 8.
So remember, anything else but Windows 7 and Windows 8,
choose .pem, else, use PPK.
Okay, that should be clear enough.
I'm going to create this key pair
and it is downloaded for me directly.
So now it is selected automatically here.
Next we have to go into network settings,
so for now, I will not touch anything.
My instance is going to get an public IP,
and then we need to connect to our instance.
And so for this, there is going to be
a security group attached to our instance
which is going to control the traffic
from and to our instance, and therefore we can add rules.
And the first security group created
will be called launch-wizard-1,
so created by the console directly,
and we can define multiple rules.
So the first rule we want to have
is to allow SSH traffic from anywhere.
So we leave it at this, and this will create a rule
in our security group to allow SSH traffic,
but we also want to allow HTTP traffic from the internet.
So I will take that box,
and this is because we're going to launch a web server
on our EC2 instance, so we need it as well.
As we're now going to use HTTPs for now,
we don't need to tick the second box.
Let's configure the storage
so then we can compare the storage and as we can see,
we have a eight gigabytes gp2 root volume
that we will leave it as is, okay,
because in the free tier, we can get up to 30 gigabytes
of EBS General Purpose SSD storage, so this is good.
And we only have one volume necessary.
If you go into advanced, you could configure them
and see a little bit more information, okay,
and the one important thing to note in here
is the delete on termination.
By default, it is enabled to yes,
I just did advanced to show you that one detail, okay?
That means that once we terminate our EC2 instance,
then that volume is also going to be deleted.
Okay, so we leave everything as is,
and we'll get back into the simple mode.
Okay.
Next for advanced details,
this is where it gets interesting.
So I will skip spot, I will skip IAM instance profile.
Don't worry, I will go over them
once we need to explore them.
I will skip all of that, so let's scroll down,
let's scroll down, let's scroll down
all the way to the bottom,
and at the bottom, there is user data.
User data is when we pass a script,
so some comments, to our EC2 instance
to execute on the first launch of our E2 instance
and only the first launch.
And therefore, on the first launch,
we want to be able to pass these commands right here.
So for this, you go into your code,
you go to the EC2 fundamentals,
and then the ec2-user-data.sh file,
you copy entirely this, so all of it,
and then you paste it here.
So you paste everything,
and that means that this script is going to be executed
when the instance is first started and only once, okay,
in the whole life cycle of the instance.
And what it's going to do
is that it's going to update a few things,
then install the HTPD web server on the machine,
and then write a file, an HTML file,
that will be a web server.
And so you don't need to know code
or know these commands, okay?
This is provided to you
to illustrate a few things on this lecture.
So finally, for summary, we want to start one instance,
this is great, and we can review everything we have here.
It all looks good.
We are very happy, and as you can see in the free tier,
we get a first year of 750 hours of t2 micro
which is reading it, running it for one month,
so that's every month.
And if you don't have a t2 micro in your region,
then it's going to be a t3 micro, okay?
And then also we get 30 gigabytes of EBS storage and so on.
So let's launch this instance
and the instance is going to be launched.
Let's go to view all instances, refresh,
and now my instance is in pending state.
So it's gonna take about 10, 15 seconds
for the instance to come up,
and this is the whole power of the Cloud.
Thanks to the Cloud, I am able to create an instance
or 100 of them very quickly in less than 10 seconds
without me owning any single server.
So that is extremely powerful,
and we just scratched the surface
of the power of the Cloud, obviously,
because the course is just getting started,
but you can get a feeling of the advances
and the speed we can have on the Cloud thanks to this.
So as you can see now, my instance is running,
and right now I wanna show you a few things, okay?
The first one is that the instance name is my first instance
and there's an instance ID
which is just a unique identifier for my instance.
There is a public IPv4 address,
this is what we're going to use to access our EC2 instance,
or there is a private IPv4 address
which is how to access that instance internally
on the AWS network, which is private.
The instance state is running,
and we get some information around host name, private DNS,
which instance that we have, so t2 micro,
as well as, if you scroll down, the AMI we're using,
which is Amazon Linux 2,
and the key pair we're using, which is EC2 Tutorial, okay?
So you can have a look at a few details in here.
You have more information, for example, on security.
We get some information on the security group
which was created called launch-wizard-1
with these in the rules.
So port 22 accessible from everywhere
and port 80 accessible from everywhere,
so you should have something similar.
Okay, if you don't, start over
because you probably missed a step.
And the add on rule allowing all communication outwards,
which allows the instance to access the internet.
For storage, we saw that, yes,
we created one volume of a gigabyte, so we're good to go.
So now let's have a look
at the web server running on my instance.
And for this, you go on public IPv4 address,
you copy this or you click on open address
and as you can see, it doesn't work.
Or if you click on it, copy,
and then paste it, you press enter, it's going to work.
So it depends on the web browsers you have and so on, okay,
but the reason it doesn't work here is that in the URL,
you need to make sure that you're using the HTTP protocol.
So HTTP colon slash slash and then the IP,
because if you use HTTPs, this is not going to work,
it's going to give you an infinite loading screen
which was happening right here.
So please make sure to use HTTP colon slash slash
and then the IP address and you're going to get this screen.
And in programming, when you do something
for the first time, usually say hello world.
So this web server is selling hello world from
and this IP right here, which is not the public IP.
This IP right here, 172-31-33-135
actually correspond to the private IPv4 address,
so this is something that I program myself.
So we use the public IP address to access it,
but we have the private IP address in here,
and we have the hello world.
And if you go too fast, you're going to get no messages.
So if you go too fast, just wait five minutes,
get back to it, refresh this page, and you'll see it.
Okay, so cool, we have a web server running, this is great.
Now let's explore a few options.
So we have an EC2 instance and it's running,
but if we don't need it, we can go to instance state
and then click on stop instance.
And in the Cloud, you can start and stop instances
just as you wish, and why would you stop an instance?
Well, the longer you leave it running,
the more you're going to pay, of course.
But if you decide to stop an instance,
then AWS will not bill you for it.
The instance state is kept
because you have a volume attached to it,
but at least you're not paying for it.
So we can see right now
while the instance is in a stopping state,
and if we try to refresh this page is going to, of course,
it's not going to work because, well,
you don't have the server running anymore.
So you can see it gets to some
like infinite loading experience, okay?
So my instance is now stopped,
and if I wanted to, actually, I could get rid of it.
And in the Cloud, it's very common to start instances
and then get rid of them very quickly just to try it out
because this is the Cloud and we can do whatever we want.
So, we can do instance state, and then terminate instance.
If we do so, we're going to get a warning message
and don't click on terminate
because I want to keep this instance with me, okay?
But this is how we would get rid of it.
So I cancel this, but what I'm going to do now
is I'm going to start my instance again.
So I go to instance state and then start instance.
And now as you can see the state is pending,
so it is getting started,
and I just wait for it to be started in the green state
and I will show you something very interesting.
Okay, so my instance is now running.
And if I go here and stop the refresh
and try again to refresh, as you can see,
it still goes into an infinite loop.
Well, you may say, well, the server is running, Stefan,
so why is it not displaying the message now?
It is displaying here, but like from the old one, of course.
So here, the IP start with 54, right?
But here, if you click on here,
now the public IP start with 3.250.
So the public IP actually has changed,
so if you stop an instance and then you start it later on,
then AWS will maybe change its public IPv4.
So therefore, you need to copy the new IPv4,
make sure to use HTTP, and voila,
we have access back to our EC2 instance.
But one thing that has not changed is the private IPv4,
the private IP will always stay the same,
but the public IPv4 may change, okay?
So, well, so that's it for this hands on.
We have seen quite a lot of things.
We've launched our first EC2 instance,
which is very exciting, our first web server in the Cloud.
We've had to look at some of the power of the Cloud.
You're just using some API calls to stop an instance,
start instance, and so on.
So I hope you liked it,
and I will see you in the next lecture.