Lecturer: Okay, so in this lecture,
we're going to create a Classic Load Balancer.
But to do so first, let's launch an instance.
Very quickly, just the way we've done it before.
we'll choose Amazon Linux 2,
a t2 micro and we'll configure it to have the web server
as we had from before.
So, if we go in here, copy the entire script
and paste it entirely,
then Add Storage.
Everything looks good.
Add Tags, Security Group.
We will use the existing security group here from before.
So, launch-wizard-1
and click on Review and Launch, and Launch.
We're going to create our EC2 Instance.
And this EC2 Instance right here
is going to have a web server.
So, I will keep this in here while it starts.
And the left hand side, I'm gonna go into Load Balancers.
So, I am in the Load Balancer consoles
and I will create my first Load Balancer.
So, I have four options available to me.
There is Application Load Balancer, Network Load Balancer,
Gateway Load Balancer and Classic Load Balancer.
So, as we can see the Classic
is sort of deprecated as Previous Generation.
So, we can still create it,
but it's discouraged by areas to use it.
We'll see ALD and NLB in the next lectures
and Gateway Load Balancer for now is out of scope.
So, let's click and create a Classic Load Balancer.
I'll call it my-demo-clb.
We'll create inside of My Default VPC
and we can make this an internal load balancer
if you wanted to keep it private.
But we want to access it from our computer.
So, we will leave this unticked
and we will also leave
the advanced VPC configuration unticked.
So, in term of Listener Configuration,
we want our Classical Load Balancer
to be welcoming HTTP traffic onto it.
So, that means that HTTP on port 80
is what we want to allow.
And then, it's going to go to the EC2 instances on port 80
for the protocol HTTP as well.
So, this is great.
Next, for security group.
We're going to create a new security group
for our Classic Load Balancer
and I will call it my-first-load-balancer-sg,
and then we can just leave the description as is.
And so, we're going to have to allow
HTTP traffic from anywhere.
So, HTTP on port 80, from and this is anywhere
as long as it's IPV4
and we can do anywhere to have IPV4 and IPV6 as well
which is not supported by the classical Balancer.
Therefore, you don't see IPV6 in here.
Okay, so we're good to go.
So next, we can configure the security settings.
And right now, we get a warning
because we're not using HTTPS or SSL,
but this is fine because right now in this sector,
we don't want to encrypt traffic in flights.
Next for health checks,
we need to look at what is going to be checked
on our instance.
As you can see, the health check
is going to talk to EC2 Instances
on the protocol HTTP, the port 80,
and the path is going to be /index-html.
So, let's ensure that it works.
So, let's take this public IPV4.
I'm going to copy the IP and open it.
And so, as you can see, we get the Hello World.
But what if we add the path?
So, /index.html onto here?
So, if you press enter, we still get the same URL.
So, this Ping Path would work.
The /Ping Path would work as well.
So, I'd like you to just have a slash.
But it should do like /foobar.
For example, for something that doesn't exist
we do like /foobar and press enter.
We're going to get an error.
And this error would make our instance unhealthy
if we kept the health check as /foorbar.
So, we wanna keep it to a path that we know works
for example, just as slash.
And if we have justice slash, then we get just a URL
and we get the Hello World back from our EC2 Instance.
So, this is perfect.
In terms of the health check,
we need to configure a timeout.
So, five second is great.
How often we want to do the health checks.
So, let's keep it at three seconds.
How many times instance needs to be unhealthy?
So, let's do it five.
Then, for it to be happy.
How many times do unhealthy counts
should be before the instant should be unhealthy.
So, two is great.
And how many times the health checks should be correct
until the instance is deemed healthy?
Let's keep it to a low number like three.
So that means that, once three health checks pass,
then instances are healthy.
And if two health checks in a row don't pass,
then it's unhealthy.
Okay, next we'll need you to add EC2 Instances.
I'm going to add this EC2 Instance
and then I will Add Tags, Create and Create.
So, our first Classic Load Balancer is created
and actually the HealthCheck timeout
must be less than interval.
So, let's review and resolve.
So, the response time out must be less study interval.
So, let's keep the response amount to five seconds,
four seconds and then create it again.
And we're good to go.
So, my Classical Load Balancer was successfully created.
So, here as our Classic Load Balancer
and we need to wait for it to come up.
So, let me pause and get back to you
when it is up and running.
If we check the video right now as you can see,
the Instance is out of service
and if you go over the info, it says,
Instance registration is still in progress.
So if you see out of service for your instance,
please wait a little bit
before asking the Q&A.
Then it gets to in-service.
So, that means that's our Classical Balancer is working.
Now, if you don't get in-service
in say a minute or two minutes,
then I will show you what may be going wrong.
So right now, let's assume that everything is working.
Please don't ask a question in the Q&A just yet.
So, we're going to open the URL DNS name
our Classical Balancer.
And as you can see,
we get Hello World from the EC2 Instance.
The same as if we had used the public facing IP.
So that means that the Classic Load Balancer is working.
But, what if it didn't work?
What if we had an instance that was unhealthy?
So, may be your Instance is unhealthy
because of security groups.
So, if we go into the security groups right now
and go to launch-wizard-1
and let's say we want to remove
these HTTP rules right here.
So, I'm going to delete these HTTP rules and save the rule.
This will make so that...
Well, this Instance right here is not accessible
from the public internet of course,
but also from the privates, it was internet because
well, there's no port 80 available on the security group.
So that means that, for example, in this example,
well, my Instance should be marked
OutOfService very quickly.
And so, right now, I see it is out of service.
So, this could be one reason
why the instance is out of service.
And the other reason why it could be out of service
is that the Hello World just doesn't work
and the bootstrap script did not execute properly.
So, these are the two reasons why this would not work.
Okay. So, let's go back into our instance.
When we had the inbound rule to be HTTP
on port 80 from anywhere on the IPV4
and save the rule.
So when we had this,
we can access our instance
both from the public IP and from the Classical Balancer
which is not working right now,
because I need to wait for my instance
to go back in service
which should take about 15 seconds.
So, that was back in service.
I refresh this and it works.
Okay, so the problem is that
we can access our EC2 Instances directly
and also, through the Load Balancer.
But we would like to tighten the security.
This is where we can show something really cool
with security groups.
We can change the inbound rule
to only allow HTTP rule on port 80,
but not from anywhere.
And instead, we want to allow it from a security group
of the Load Balancer.
So, my first Load Balancer.
So, we are allowing any traffic
from the security group of the Load Balancer
into the security group of the EC2 Instances.
So, allow only traffic
from the ELB.
And the reason we do so is that we want the ELB
to access our instance, okay?
But we don't want our users
to directly access our instances as you can see now.
If I refer to this page, I get an endless running cycle.
And in here, if I refresh,
well, it still works.
So, we can access our EC2 Instances only now,
through the Load Balancer.
So, we have enhanced the security
and that is a very, very common pattern in AWS.
So finally, let's show the whole power of Load Balancing
by having more instances.
So, I can ran click
and say Launch instance from this templates.
For example, oops!
Right click and say Launch instances
and then use the one.
So, we'll use t2 micro
and for instance details, we're good to go.
We can also provide the user data
just like we had from before.
So, let's provide it
and Add Storage,
Add Tags, Security Group, Review and Launch.
So, we will pass in the launch-wizard-1 security group.
Launch, and yes, we have the key pair.
That's one of them and we can do another one like this.
So, we will launch an instance again.
Select, we have t2 micro.
I'm trying to go a little bit fast here.
Paste the users data.
Storage is good.
Security Group, we're going to do launch- wizard-1,
Review and Launch, and Launch, okay.
So, the effect of this is that
now we have three EC2 Instances that are launched
and they will all have their own Hello Hello World message.
And so, what I want to do
is to (indistinct) these instances
on to my Classical Balancer.
So, I go to my Classical Balancer,
I edit my instances
and now I add these two new instances.
So now, we have three instances
registered on my Classical balancer
and as you can see, two are OutOfService
because they're still booting up.
So, what's going to happen
is that we need to use our data script
on the EC2 Instances to complete successfully.
And then, once the EC2 Instances are up,
they should be put in service by our Load balancer.
And again, if you see OutOfService,
this maybe because you don't have
the user data script run properly
or some security group issues.
But if you see some inservice and some OutOfService,
and they have the same security groups,
then it's not a security group issue, okay?
So, let's just switch a little bit for this to complete.
Okay, so my three instances are in service
and they're spread across two availability zones.
So, us-east-2a and us-east-2c.
And so now, if I go back to my load balancer
and refresh the page,
every time I refresh,
I'm going to get a new EC2 Instance replying to me
and therefore we get a new Hello World message
from a different private IP.
So, this shows that every time I refresh the browser,
my request goes to a different EC2 Instance
and that means that my load balancer indeed
is load balancing my requests.
So, this is pretty cool.
And that concludes the demo for the Load Balancers.
So, that's it for this demo.
Please delete the Classical Balancer.
We will not be using it.
But keep the EC2 Instances running during the section
as we'll be creating new Load Balancers
and using them as well.
So, that's it.
I will see you in the next lecture.