A target group tells a load balancer where to direct traffic to : EC2 instances, fixed IP addresses; or AWS Lambda functions, amongst others. When creating a load balancer, you create one or more listeners and configure listener rules to direct the traffic to one target group.
The port the load balancer uses when performing health checks on targets. If the protocol is HTTP, HTTPS, TCP, TLS, UDP, or TCP_UDP, the default is traffic-port , which is the port on which each target receives traffic from the load balancer. If the protocol is GENEVE, the default is port 80.
- Login to aws portal.
- Click on Services.
- Under Compute select EC2.
- Click on Target Groups.
- Click on Create Target Group.
- Provide Target group name.
- Select Target type :Instance ,IP(Network load balancer) or Lambda function(An application).Select Instance Target type for application load balancer.
- Select Protocol like HTTP, HTTPs, TCP or UDP. The protocol load balancer uses when routing traffic to targets in this target group.
- Provide Port Number, Load balancer port uses when routing traffic to targets in this target group (1-65535).
- Select existing VPC.
- Then select protocol for health check settings, The protocol of load balancer uses when performing health checks on targets in this target group.
- Set the path for health checks.
- At Advanced health check settings, Select port:traffic port or override.
- Provide healthy threshold & Unhealthy threshold.
- If health checks consecutively exceed the Unhealthy threshold count then the load balancer takes the target out of service. If health checks consecutively exceed the Healthy threshold count, the load balancer puts the target back in service.
- Set Timeout and the amount of time in seconds during which no response means a failed health check (2-120 seconds)
- Set the Interval and the approximate amount of time between health checks of an individual target (5-300 seconds).
- Set the success code and the HTTP codes use when checking for a successful response from a target.
- Then click on Create.
- After sometime target group is ready.
Create Target Group using Shell
- Setup aws-cli on your system so click on link https://www.hackerxone.com/blog/how-install-configure-aws-cli-ubuntu-1804
- Run the following command:
- To create a target group to route traffic to instances registered by instance ID.
aws elbv2 create-target-group –name example –protocol HTTP –port 80 –target-type instance –vpc-id vpc_id
2. To create a target group to route traffic to an IP addresses.
aws elbv2 create-target-group –name example –protocol TCP –port 80 –target-type ip –vpc-id vpc_id
3. To create a target group to route traffic to a Lambda function.
aws elbv2 create-target-group –name example –target-type lambda