-: Okay. So let's practice creating an application balancer
of type HTTP and HTTPS.
So let's create it, and we can have a look
at how application balances work.
We have a really nice graph around it,
but we know this already.
So what is the name going to be?
Well, it's going to be DemoALB
and we can either have an internet-facing ALB
or an internal facing ALB, but this is for private traffic.
So, because we want to publicly access our application,
currently, we're going to use an internet facing scheme.
Then we're going to use an IPv4 type of stack
for getting access to our load balancer.
Okay.
Next, in terms of network mapping, we have to specify a VPC
we're going to operate in, as well as how many subnets
and AZs we want to operate in.
So I'm going to take all three subnets,
so, eu-west 1b, 1c, and 1a
and they will automatically get the right sub-net
assigned to them.
Perfect.
Next, we need to assign a security group
to our load balancer. So we already have created one.
So my first load balancer security group
is going to be assigned to it.
And then we need to specify listeners and routing.
So this is saying, hey,
if someone is accessing our load balancer on,
from the protocol HTTP on port 80, then forward to,
and we need to create a target group for this.
So we go ahead and create a new target group.
And that's going to be based on instances
so you have different target groups possible
for our ALB. Could be instances, IP addresses,
Lambda function or an ALB,
but this is only when we're using an ALB.
So the one we want to use right now is instances.
So this is, we want to have
the ALB sent data into our network traffic,
into our EC2 instances.
So the target group name is going to be
"my-first-target-group".
And the protocol is, HTTP port 80.
The VPC is this one. HTTP1 is fine.
And then we're going to scroll down,
health checks so we can specify
some advanced health check settings for it too.
So number of health is going to be three.
Unhealthy is going to be two,
timeouts going to be four seconds
and interval is going to be five seconds.
Okay. So this is good. And the success code is 200.
So we'll click on next,
and then we're going to register two
out of the three instances we have.
So make sure to only include two
and I'll show you why after. Okay.
So review targets,
We have two targets out of the three available instances.
So now let's create this target group.
So it has been created, now back into our load balancer.
We can refresh this and select my first target group.
Very nice.
So here's a summary. We have a DemoALB,
internet-facing on IPV4.
Attached to it is one security group.
Network mapping is, has three AZs
and port 80 HTTP redirects to my first target group.
Okay. Let's create this load balancer and now we're done.
So let's view the load balancers
and now we have to wait for it to be provisioned.
Okay, so my ALB is now provisioned
and I can go to my DNS name, open it.
And then I get the hello world from the IP.
And if I refresh again, I get the different Hello World
from a different EC2 instances.
So my ALB is working as expected,
just like the CLB did,
but because this is an application balancer,
we get some added benefits.
And so to prove this to you,
I'm going to go into target groups
and I'm going to create a second target group.
So we have my first target group,
I'm going to create a target group based on instances,
and I'll call it "my-second-target-group".
And then we have this VPC, which is perfect,
We have HTTP1,
scroll down the health check just looks like before,
so healthy threshold three, unhealthy,
timeout four, interval five.
Here we go and click on next. And then I can register,
I can't remember which one it is, but one missing instance.
The one that is not,
it doesn't really matter which one you choose.
But anyway, I will just add one instance
for the sake of this purpose, once I decide,
and I will include as pending below,
which is a target for my target group,
create this target group.
And now we have a second target group.
So the cool thing is that if we go back into our ALB,
now we can have multiple listeners
redirect to multiple target groups.
So right now we have one listener port 80
that is forwarding to my first target group.
But we can view and edit the rules of this listener
to start leveraging other target groups.
So I can add a rule in here and I can say, okay,
if the path is, for example, slash tests,
then you should forward your response
to my second target group.
And the idea behind this is that, okay, now if we save this,
well, we have two rules and the first one
that's going to be evaluated is the path.
And it goes to my second target group if it matches,
else by default, you should route to my first target group.
And we can insert manuals.
For example, we can say, if the path is slash constant,
then return a fixed response,
which Is maybe 4 0 4, constant error response,
whatever you want to think of.
And again, save this.
And now we have different rules for our load balancer,
so you can create it,
but you can see how we are way more powerful
than the classic load balancer.
And we can do routing based on path, host header,
HTTP header, query string, source IP and so on.
So you can get very creative with this load balancer.
So let's, let's try it out, let's check it out.
So we go to the DemoALB, we take the DNS,
which is right here, which is already open in here.
So, this works, for now we are only gonna get two instances.
If I do slash constant,
I'm going to get the constant error response
directly sent by my load balancer,
and if I go to slash test, well, it's not going to work.
I'm going to get a not found because my EC2 instance
is not configured to reply to the slash test type of query.
But this query is actually being redirected
to my secondary group, which sort of proves the point
I was trying to make.
So to finish this, let's go and clean it up.
So in the listeners,
I can just remove some rules that I've created.
So these two will be removed.
I will delete them, then back into my target groups.
I will delete my second target group.
And in my first target group,
I'm going to just register one more target.
So I will register targets and make sure that,
I can't remember which ones, so I'll add them three
and then, okay.
One, Okay. This one is being added. So that's perfect.
Click on register pending targets.
And here we go.
So as you can see, this is the target group now,
which will perform the health checks
and make sure that all the instances are healthy.
So now three instances that are healthy out of three.
So this is perfect.
So that means that if we go back into our load balancer,
at the root of the URL, we get hello world from one,
two, and three kind of instances. So that's perfect.
Our target group is working properly.
So is our ALB and that's it.
So I hope you liked this lecture
and I will see you in the next lecture.