Hey, everyone, and welcome back.
Now, in the earlier set of videos we were discussing about the basics of the application load balancers.
So today is going to be the practical session where we'll go ahead and configure the entire setup.
Now, before we do that, let's go ahead and quickly launch a new easy to instance the name, I'll just
call it as LP hyphen instance.
Let's go a bit down.
You can configure your key pair and you can go ahead and launch your instance grid so the time instance
is getting launched.
Let's go back to the ESI two console and if you go a bit down, you have a load balancing section where
you have the load balances and you have the target group.
Now the first thing that we'll configure is the target group.
Let's open this up and within here we'll create a target group.
Now within the target group, we'll be selecting the target type as instances over here.
Let's go a bit down.
You can give a target group name.
I'll just call it as demo hyphen G.
We'll leave everything as default over here.
Let's go a bit down.
Let's click on next.
And within here you have an AC two instance.
Let's go ahead and select it.
I'll click on include as pending below.
Let's go a bit down.
We'll go ahead and we'll click on Create Target Group.
Not before creating a load balancer.
Let's also configure a web server on this AC two instance so that it can serve some traffic.
So from my terminal, let me go ahead and quickly connect to the AC two instance.
Let's switch to the root user.
And let's quickly run the Yum install engine x command, which will give us the Amazon Linux Command.
I'll copy this.
Let me add it here.
Either way for confirmation and I'll press enter once the engine X is installed, you can go ahead and
quickly start the Engine X Warrior.
Great.
One more thing that you will have to modify here is the security group to make sure that the Port eight
is allowed.
So I'll edit the inbound rules.
Let's add a new rule of Port eight and I'll allow it for everyone.
Perfect.
So let's go back to our instances.
Let's copy the public IP and I'll add it within the browser.
And as expected, we are seeing the default engine express.
Great.
Now let's go back to the load balancing and we'll now create a load balancer.
Let's click on Create Load Balancer.
The load balancer type would be an application load balancer.
The Load Balancer name.
Let's just call it as demo hyphen LP.
Let's go a bit down.
We'll leave these things as default.
The scheme would be internet facing and the IP address would be IPv4.
Let's go a bit down within here.
You can select the availability zone.
Now, one important thing that needs to be noted is you have to verify that the AC to instance is part
of these availability zones.
So in fact, let's quickly open up our easy to instance.
So if I select this easy to instance, if I go to networking within here you have the availability zone,
you have availability zone of us test one B, so make sure that is selected.
You will have to select two availability zones while creating an application load balancer.
You can go a bit down within the listeners and routing.
You can go ahead and select your target group.
Let's go a bit down.
Let's go ahead and create a load balancer.
Alright, so now it is giving us a node that it might take a few minutes for the load balancer to be
up.
That is fine.
Let's click on view load balancer here.
Now, one important thing that needs to be noted is the security group of the load balancer.
Now there is a DNS name that is associated with it.
So client will be making a request to the load balancer.
So you have to make sure that the security group of the load balancer accepts the request so you can
go ahead and verify what security group is associated with the LP and then you can go ahead and modify
the rules associated with it.
So in this case, there is a default security group for the security group.
Let's click on inbound rules and within here we'll click on edit inbound rules and make sure to add
a rule of eight to allow everyone to connect to the load balancer grid.
Now if you quickly open up LP, let's refresh this page.
The state is still provisioning.
That is completely fine.
So till that time the load balancer is in the provisioning state.
Let's go to listeners over here and let's go ahead and click on view edit rules.
So there is one rule that is created which sends all of the request to this demo target group, which
is nothing but the easy to instance.
So any request that goes to the load balancer, it will automatically be forwarded to our EC two instance.
You can go ahead and add another set of rules as well in case if you'd like.
So let's click on Add a new rule.
I'll click on insert rule and within you can add a condition and within your let's say I'll add a condition
based on the HTTP header of user hyphen agent and the value, let's say call.
And within the actions you have forward to where you can follow to service.
You have a redirect to or you have a return fix response.
So in a return fix response, let's say response code is 200 and I'll say hi, call on it and I'll click
on See.
So now what will happen is any time a request to this load balancer is made using a call client, then
automatically this response will be sent off.
If any request is made to the load balancer, which does not match this force rule, then that request
will be forwarded to our AC to instance, where you have the default engine page that is running.
All right, so let's go to the description here.
And at this stage, you see the state is active, so I'll copy the DNS name and from the browser, let
me add the DNS name.
And as expected, we are getting this default engine next page.
Now since we had one more rule associated with call what we can do from the ESI two instance itself,
you can try the curl utility so the curl is present.
So let's do a call and I'll add the DNS name.
If I press enter somehow, this time again, you see that you have an engine page that is coming up
instead of high cycle.
So let's quickly look into what mistake we might have done.
Let's go to the listeners over here.
Now, what you can do is within this user agent header, it can happen because Curl has multiple versions
and each version would send a different user agent header.
So what you can do in such cases, let's edit this and I'll add the star over here.
So irrespective of what version of curl that you are running, it will match this specific rule.
So let's clear the screen.
Let's run the curl command.
And this time you see we are getting a curl message.
So just to revise on why the issue had occurred in the first case we had just specified curl.
Now let's say that I am running a call of version 1.4.
So in such cases, sometimes the user agent looks something like this, which is curl 1.4 or 1.8, and
this is one of the reason why the request was not matching the rule that we had created, and that is
why we had added a star mark which will match all the user agent that has the specific goal in it,
irrespective of the version.
All right.
So I hope that this you understood the basics of the application load balancer.