Okay, let's continue with our demo. We have deployed our PHP web app, with three tasks running and three instances. Now, we want to set up a load balancer in front of those containers. Let's go to the EC2 console and create a load balancer. We'll name it phplb. We'll create it in the VPC because, by default, a new ECS cluster runs inside its own VPC. Port 80 is what we want. I'll select the subnets and create a new security group for the load balancer, opening port 80. I'll set the health check to index.php and reduce the timeouts to the smallest value possible to save time. This is just a demo; please use longer values in production. I'll add my instances here. Remember the rule: tag everything. Otherwise, it's hard to find out what's doing what after a while. My load balancer is created and will ping those instances to bring them into service. They're currently out of service, so it will take a few minutes.
While we wait, let's look at the auto scaling groups. When you create an ECS cluster, EC2 creates an auto scaling group, which is how it controls the number of instances running in the cluster. As you can see, the desired and max are both set to 3, so I have three instances running in multiple availability zones, providing automatic high availability. Let's add the load balancer to this group. If we don't, and we scale the cluster, only the initial three instances will be load balanced, which is not what we want. We want all instances in this group to be load balanced. Let's save this, and now every new instance launched in this auto scaling group will be load balanced.
Let's go back to the load balancer and see if the instances are in service yet. Not yet; it takes a little while. I'll pause the demo for a moment and be back shortly.