Target Groups
In this article:
Target Groups#
One or more target groups must be created for the load balancer to work. Each target group includes one or more targets among which requests are distributed. The target is identified by a combination of instance ID and port number.
Traffic is routed to the target group specified in the traffic listener. To balance different request types, you can create multiple listeners and corresponding target groups. Routing is performed independently for each target group.
The same target group can be used by several listeners, but only by one load balancer. In other words, all listeners using a particular target group must belong to the same load balancer.
You can add and remove targets from a target group. The same target resource can belong to different target groups.
Health check#
The target health check ensures that requests are only directed to active target resources. If necessary, you can modify the default settings.
The health check method employed depends on the target group type (TCP, UDP, or HTTP):
in case of a TCP target group, the load balancer expects to receive a
SYN-ACKpacket in response to aSYNrequest;in case of a UDP target group, the load balancer expects that a UDP packet will not return
ICMP Unreachable(Type 3with anyCodevalue);in case of an HTTP target group, the load balancer expects to receive a predefined HTTP code (by default,
200) in response to a health check request. You can configure an HTTP path for checking availability of targets and an HTTP response code, that indicates that the target is available.
If all registered targets in a target group are unavailable, the ALB returns HTTP 503 Service Unavailable in response to the user request, while the NLB ignores incoming requests.
Target state#
Based on the check results, the target may be in one of the following states.
State |
Description |
|---|---|
|
Target is healthy |
|
The target is unhealthy: it is not responding to requests, has failed a health check, or is stopped. |
|
The target is not registered in the target group, or the target group is not included in the listener rule. |
Target state codes#
If the target state is other than Ready, the cause can be found in the Targets tab on the target group page where its code and description are displayed. The state code can also be found using the DescribeTargetHealth API method.
State code |
Description |
|---|---|
Target.NotInUse |
The target group is not configured to receive traffic from the load balancer. |
Target.NotRegistered |
The target is not registered in the target group |
Target.Timeout |
Response timeout |
Target.ResponseCodeMismatch 1 |
Health check failed, code [code] |
Target.FailedHealthChecks 1 |
Health check failed |
Create target group#
Note
Only instances in the Running state can be added to the target group. They must be in the same VPC as the load balancer to be associated with this target group.
To create a target group:
Go to the section Load Balancing Target Groups and click Create.
Specify target group parameters:
Name tag – Optional description of the target group.
Target group name – The name must not be longer than 32 characters, can only contain Latin letters, numbers and hyphens, and must not start or end with a hyphen.
Protocol – Protocol used to transmit traffic (TCP or UDP for a network load balancer and HTTP for an application load balancer). It must be the same as the protocol specified in the listener.
Port – The default port for receiving traffic. It will be assigned to the target if no other port is specified.
VPC – VPC in which targets are located.
To go to the next step, click Next.
Set the health check settings.
Note
For an HTTP target group, you can also use the ModifyTargetGroup API method to specify a path for checking the target availability and an HTTP response code indicating that the target is available.
Healthy threshold – The number of successful health checks before the resource is considered available.
Unhealthy threshold – The number of failed health checks before the resource is considered unavailable. In case of a network load balancer, this parameter is automatically set equal to the healthy threshold.
Interval – Period between health checks of a target.
Timeout – The time, after which the check is considered failed if there is no response. This value is for reference only and cannot be changed.
To go to the next step, click Next.
Register instances in a target group.
Note
You may skip this step and register targets later.
Select instances from the drop-down list.
Change the default port if necessary. You can specify multiple ports separated by commas. In this case, a separate target with the selected port will be created for each selected instance.
Click Add to include instances with the specified ports in the target group.
Check the list of resources to be added. If necessary, you can right away add more targets by repeating the steps above, or delete unnecessary ones by clicking Delete targets.
To go to the next step, click Next.
If required, assign tags to the target group.
If the Name tag was not specified in step 2 and you want to add it, click Add Name tag and set the tag value.
To add an arbitrary tag, click Add tag and enter tag key and value.
To go to the next step, click Overview and Create.
Double-check all the set parameters and targets and click Create.
Register targets#
If necessary, you can add more targets to an existing target group, for example, when their performance becomes insufficient or some target becomes unavailable.
Go to the section Load Balancing Target Groups.
Select the target group from the list and click Register resources. Alternatively, click the target group name to go to the group page, open the Targets tab, and click Register targets.
Add instances to the target group:
Select instances from the drop-down list.
Change the default port if necessary. You can specify multiple ports separated by commas. In this case, a separate target with the selected port will be created for each selected instance.
Click Add to include instances with the specified ports in the target group.
Check the list of resources to be added. If necessary, you can right away add more targets by repeating the steps above, or delete unnecessary ones by clicking Delete.
Click Register to register targets.
Change settings to check health#
Go to the section Load Balancing Target Groups.
Select the target group from the list and click Edit health check settings. Alternatively, click the target group name to go to the group page, open the Health check tab, and click Edit health check settings.
Edit the health check settings:
Note
For an HTTP target group, you can also use the ModifyTargetGroup API method to modify a path for checking the target availability and an HTTP response code indicating that the target is available.
Healthy threshold. For an NLB target group, the unhealthy threshold will be automatically modified and set equal to the healthy threshold.
Unhealthy threshold. For an NLB target group, the healthy threshold will be automatically modified and set equal to the unhealthy threshold.
Interval between health checks.
Click Modify to apply the new settings.
Deregister targets#
To exclude targets from the group:
Go to the section Load Balancing Target Groups.
Click the target group name to go to the group page and open the Targets tab.
Select from the table the targets you want to deregister, and click Deregister.
Attention
The operation is performed without additional confirmation. If necessary, you can easily again register resources, which you deregistered.
Create a balancer with an associated target group#
You can create a load balancer directly in the Target Groups section. It will be associated with the selected target group, so you won’t have to set parameters of this target group. This feature is available for groups only if they are not associated with any listener.
Note
An Internet-facing load balancer can only be created if the target group is placed in the VPC with an attached Internet gateway.
To create a balancer and associate it with a target group:
Go to the section Load Balancing Target Groups.
Select the target group from the resource table and click Create load balancer.
A balancer wizard opens. It is similar to the standard wizard. Follow steps 1 and 2 to configure the basic parameters and associate the balancer with a network.
Add listeners. You don’t need to specify a target group to which the listener forwards traffic, since the selected target group is used to this end. If forwarding to other target groups is required, it can be set up after creating the balancer by adding listeners. To add other listeners, click Add.
In the last step, check the configured load balancer parameters and click Create.
Add listener for a target group#
You can add a listener for the selected target group directly in the Target groups subsection and avoid specifying its parameters. The listener adding procedure is slightly different depending on whether the target group is associated with a load balancer or not.
To add a listener:
Go to the section Load Balancing Target Groups.
Select the target group from the resource table and click Add listener.
If the group is not associated with any load balancer, select a load balancer from the drop-down list. Set the port the listener will use to receive traffic.
If you want to assign tags to the listener, click Add tags to go to the next step.
If the Name tag was not specified and you want to add it, click Add Name tag and set the tag value.
To add an arbitrary tag, click Add tag and enter tag key and value.
Click Add.
Delete target group#
Note
The target group can only be deleted if not used by any listener. Deleting a target group only deletes the group itself. Instances included in it as targets are not deleted.
To delete a target group:
Go to the section Load Balancing Target Groups.
Select the target group from the list and click Delete. Alternatively, click the target group name to go to the group page, open the Information tab, and click Delete.
To confirm the action, click Delete.
Target group information#
The resource page displays data about the target group, its resources, along with their quantities and parameters, health check settings, and other useful information. To open the specific target group page, go to the section Load balancing Target groups and click its name in the resource table.
The Information tab shows general information about the group:
target group name (Name tag);
type of targets included in it;
load balancer to which the group refers;
protocol used to transmit traffic to the target group;
port to which traffic is transmitted;
VPC in which the target group is created;
ARN of the target group;
number of targets in the group.
Moreover, here you can create a load balancer, add a listener and delete a group.
The Targets tab displays a table with details of resources in the target group:
instance ID;
port at which traffic is received;
target status;
the reason why the target is in this status;
description of the reason.
In addition, here you can register additional resources or deregister existing resources.
In the Health check tab, you can view the health check settings and modify some of them:
protocol used for health check;
port used for health check;
healthy threshold;
unhealthy threshold;
interval between health checks;
waiting time for a response, after which the check is considered failed.
The Tags tab displays information about the assigned tags. Here you can also assign tags to the target group.