Once we have placed autoscaling for our EC2 instances, we might want to put load balancing for these instances. That is where ELB comes in. ELB automatically distributes incoming traffic across multiple EC2 instances. It scales up and down according to the receiving traffic. When there are multiple EC2 instances running behind ELB, it will perform periodic health checks and terminate traffic flow if these health checks get failed. In case of a autoscaling group taking care of EC2 instances and it adds a new instance, ELB will automatically notice the new instance and will start health checks.
In addtion to health checks, ELB also can use to SSL termination, where it will offload the certificates and allow unencrypted traffic to flow inside the subnets.
ELBs can be spread accross multiple availability zones for higher fault tolerance.
In this example I will create an ELB to manage traffic flow to an EC2 instance provisioned using an autoscaling group.
Let me first declare our autoscaling group in autoscaling.tf,