تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Creating the Load Balancer0:00

Let's start by creating our load balancer. I'm going to configure all the resources inside the infrastructure.yaml file we created earlier, which is in the same repo as our application code. However, I recommend that you create a separate repo for infrastructure code separate from all your apps. That way, you can manage all your infrastructure configurations from one place, and you can control access to this code if needed. Anyway, let's create the load balancer resource, we're going to call it ApplicationLoadBalancer, and it's going to be of type AWS Elastic Load Balancing v2 LoadBalancer. For the properties, we're going to set the scheme to internet-facing, and we're going

and it's going to be of type AWS Elastic Load Balancing v2 LoadBalancer. For the properties, we're going to set the scheme to internet-facing, and we're going to attach this ApplicationLoadBalancer to a security group, and we're going to import the value of the security group from the Laracast VBC CloudFormation stack. Then for the subnets, we're going to import the public subnet 1 from the Laracast VBC stack, and also import public subnet 2. So this load balancer will be on two public subnets. Now let's create a target group resource. And a target group is as the name indicates, a group of targets. In our case, those targets will be two EC2 instances.

Defining the Target Group1:31

And a target group is as the name indicates, a group of targets. In our case, those targets will be two EC2 instances. We will then configure the load balancer to direct traffic to this target group. So let's create a resource called EC2 target group. This one is of type AWS Elastic Load Balancing v2 target group. For the properties, we're going to give it a name. And for the protocol, we're going to choose HTTP. This is the protocol to use for routing traffic to the targets. We will route traffic without encryption as we mentioned earlier. Now for the protocol version, we're going to choose HTTP 1, but you can use HTTP 2 as

Configuring Targets and Health Checks2:09

We will route traffic without encryption as we mentioned earlier. Now for the protocol version, we're going to choose HTTP/1, but you can use HTTP/2 as well if you want. For the VBC ID, we're going to import the value of the VBC from the Laracast VBC stack. And for the port, we're going to set it to port 80. Now for the target group attributes, we are going to set this key, deregistration delay, timeout seconds. This is the amount of time for the balancer to wait before terminating connections to a target that is being removed. And to explain this further, let's say we want to stop one of the instances at some

a target that is being removed. And to explain this further, let's say we want to stop one of the instances at some point in the future. The load balancer will stop sending traffic to this instance while it's being deregistered from the target group. The balancer will keep any open connections in order not to fail requests. But after some time, it will forcibly close those open connections so it can mark the target as unused so we can safely stop it. We will set this value to 31 seconds. Now for the targets, we're going to add our EC2 instance 1 target and EC2 instance 2 as

We will set this value to 31 seconds. Now for the targets, we're going to add our EC2 instance 1 target and EC2 instance 2 as well. Then we are going to configure the health check interval seconds. We're going to set it to 30. That's the time between health checks. Then for the health check timeout seconds, we're going to set it to 5. And this is the timeout before we consider a check as failed. Now for the unhealthy threshold count, we're going to set it to 2. And this is basically the number of failed requests before we consider a target as unhealthy.

Deploying the CloudFormation Stack4:05

Now for the unhealthy threshold count, we're going to set it to 2. And this is basically the number of failed requests before we consider a target as unhealthy. For the healthy threshold count, we're going to set it to 5. And this is the number of successful requests before we consider an unhealthy target as healthy again. And for the health check path, we're going to set it to the root path. And this is basically the path that will be used for the health checks. Alright, let's deploy our stack to make sure that what we have configured so far is correct. I'm going to paste the command we executed earlier to deploy our infrastructure stack. And then I'm going to wait for the updates to complete.

Verifying Target Group Status4:48

I'm going to paste the command we executed earlier to deploy our infrastructure stack. And then I'm going to wait for the updates to complete. Here we go. Let's go check the target group. We will open the CloudFormation stack, check the Resources tab, and locate the target group. And here we go. This target group has two targets, which are our two instances. The health status of the targets are unused. And that's because we haven't attached the target group to the load balancer yet. That's what we will do in the next video.

And that's because we haven't attached the target group to the load balancer yet. That's what we will do in the next video.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟