‫So let's have a look
‫at a few more advanced concepts for our load balancer.
‫Number one is around network security.
‫So currently, we access this load balancer
‫through a security group here.
‫This is my load balancer security group.
‫And then we access our EC2 instances
‫through their own security group.
‫So right now, if I look at the public IP and access it,
‫as you can see, I can access my EC2 instance directly,
‫or I can access it, of course, through my load balancer.
‫But it may be preferable
‫to only access my EC2 instance through my load balancer.
‫So how do we do this?
‫Well, under instances,
‫let's go for security groups, so right here.
‫And we're going to look
‫at the launch-wizard-1 security group.
‫And in here, for the inbound rules, we're going to edit them
‫and we're going to look at the HTTP rule.
‫Right now, we allow everything
‫from everywhere on this security group
‫but we're gonna say is that no, the only traffic allowed
‫in to our EC2 instance should be traffic coming
‫from the load balancer.
‫So how do we change this?
‫Well, let's first delete this rule.
‫You have to first delete it and then you add a new rule.
‫And so again, we want HTTP.
‫But this time, instead of having a CIDR block,
‫you can scroll down and you can see
‫that you can have security groups in there.
‫So the security group we want to allow in
‫is the security group of my load balancer.
‫So if you just type load as well,
‫it's going to filter the list.
‫So then you select the security group of the load balancer.
‫And the effect of this is that,
‫if we save this rule and have a look at it.
‫Now, if we have a look at our EC2 instance directly
‫and I refresh this page, as you can see, it's timing out,
‫because it's not being able to access the instance
‫because I'm not allowed to access directly, the instance.
‫But if you refresh the load balancer, well the low balancer
‫can still access my instances because in the rule
‫that we have created in our security group,
‫we allow inbounds coming from,
‫if you have a look at here, we allow inbound coming
‫from the security group of the application load balancer.
‫So here we have tightened network security.
‫The second thing I want to show you
‫is around application load balancer rules.
‫So currently, if you go into this ALB right here
‫and we go under listeners and I click on it,
‫as you can see, I have a rules section.
‫And the rule is saying that right now,
‫you send everything to my demo target group ALB.
‫But it's possible because we have
‫an application load balancer to manage rules
‫and to make a few rules.
‫And so let's have a look at the rules we can add.
‫So we can add a rule here, for example, insert rule.
‫And here we can have conditions
‫based on how the request looks like.
‫And so we can say,
‫"If the host header has a specific value,
‫then send to a different target group."
‫Or, "If the path is different,
‫then again send to a different target group."
‫Or for example, let's have a play,
‫"If the path is /error, then return a fixed response
‫of code 404 and saying, 'Not found, custom error'."
‫Let's save this.
‫And now we have, if the path is /error,
‫then return a fixed response.
‫We could have other rules.
‫For example, if the path is /other-service,
‫then forward to, and then another target group
‫that we could define in here,
‫but we don't have one right now.
‫Or for example, if the path is other service,
‫then we can delete this and we can say,
‫redirect to HTTPS, or HTTP with a different path
‫and a different status.
‫So as you can see, we can have a lot
‫of complex rules in here in our load balancer,
‫and this is why we wanna use
‫an application load balancer when it comes to HTTP.
‫So let's just test our special path /error.
‫So I go back in here and I go to my load balancer.
‫So here's my demo ALB, I will copy the DNS name.
‫So if I paste this one, well,
‫of course we get our EC2 instances or two.
‫But then if I do /error, it says, "Not found, custom error."
‫And so I get a custom error message, so it's working.
‫So that's it for load balancer.
‫We've seen a couple of advanced features.
‫I hope you liked it, and I will see you in the next lecture.