A load balancer serves as the single point of contact for clients. The load balancer distributes incoming application traffic across multiple targets, such as EC2 instances, in multiple Availability Zones. This increases the availability of your application. You add one or more listeners to your load balancer.
A listener checks for connection requests from clients, using the protocol and port that you configure, and forwards requests to one or more target groups, based on the rules that you define. Each rule specifies a target group, condition, and priority. When the condition is met, the traffic is forwarded to the target group. You must define a default rule for each listener, and you can add rules that specify different target groups based on the content of the request (also known as content-based routing).
Each target group routes requests to one or more registered targets, such as EC2 instances, using the protocol and port number that you specify. You can register a target with multiple target groups. You can configure health checks on a per target group basis. Health checks are performed on all targets registered to a target group that is specified in a listener rule for your load balancer.
Edit application-load-balancer.json and update the values of %publicSubnet1%, %publicSubnet2%, and %loadBalancerSecurityGroup% from the CloudFormation stack outputs. Save the file. Create the application load balancer:
aws elbv2 create-load-balancer --cli-input-json file://application-load-balancer.json
Please note the ARN of the application load balancer for use in an upcoming step.
Browse to the Load Balancer console to check out your newly created load balancer.
Edit target-group.json and update the value of %vpc% from the CloudFormation stack outputs. Save the file. Create the target group:
aws elbv2 create-target-group --cli-input-json file://target-group.json
Please note the ARN of the target-group for use in an upcoming step.
Edit modify-target-group.json and update the value of %TargetGroupArn% with the ARN. Save the file. Modify the target group:
aws elbv2 modify-target-group-attributes --cli-input-json file://modify-target-group.json
Browse to the Target Group console to check out your newly created target group.
Edit listener.json and update the values of %LoadBalancerArn% and %TargetGroupArn% from the previous steps. Save the file. Create the listener:
aws elbv2 create-listener --cli-input-json file://listener.json
Browse to the Load Balancer console to check out your newly created listener by selecting your load balancer and clicking on the Listeners tab.