class ApplicationTargetGroup (construct)
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.ElasticLoadBalancingV2.ApplicationTargetGroup |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awselasticloadbalancingv2#ApplicationTargetGroup |
Java | software.amazon.awscdk.services.elasticloadbalancingv2.ApplicationTargetGroup |
Python | aws_cdk.aws_elasticloadbalancingv2.ApplicationTargetGroup |
TypeScript (source) | aws-cdk-lib » aws_elasticloadbalancingv2 » ApplicationTargetGroup |
Implements
IConstruct, IDependable, ITarget, IApplication
Define an Application Target Group.
Example
declare const alb: elbv2.ApplicationLoadBalancer;
const listener = alb.addListener('Listener', { port: 80 });
const targetGroup = listener.addTargets('Fleet', { port: 80 });
const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'DeploymentGroup', {
loadBalancer: codedeploy.LoadBalancer.application(targetGroup),
});
Initializer
new ApplicationTargetGroup(scope: Construct, id: string, props?: ApplicationTargetGroupProps)
Parameters
- scope
Construct - id
string - props
ApplicationTarget Group Props
Construct Props
| Name | Type | Description |
|---|---|---|
| cross | boolean | Indicates whether cross zone load balancing is enabled. |
| deregistration | Duration | The amount of time for Elastic Load Balancing to wait before deregistering a target. |
| enable | boolean | Indicates whether anomaly mitigation is enabled. |
| health | Health | Health check configuration. |
| ip | Target | The type of IP addresses of the targets registered with the target group. |
| load | Target | The load balancing algorithm to select targets for routing requests. |
| multi | boolean | Indicates whether the target group supports multi-value headers. |
| port? | number | The port on which the target receives traffic. |
| protocol? | Application | The protocol used for communication with the target. |
| protocol | Application | The protocol version to use. |
| slow | Duration | The time period during which the load balancer sends a newly registered target a linearly increasing share of the traffic to the target group. |
| stickiness | Duration | The stickiness cookie expiration period. |
| stickiness | string | The name of an application-based stickiness cookie. |
| target | Target | Configuring target group health. |
| target | string | The name of the target group. |
| target | Target | The type of targets registered to this TargetGroup, either IP or Instance. |
| targets? | IApplication[] | The targets to add to this target group. |
| vpc? | IVpc | The virtual private cloud (VPC). |
crossZoneEnabled?
Type:
boolean
(optional, default: use load balancer configuration)
Indicates whether cross zone load balancing is enabled.
deregistrationDelay?
Type:
Duration
(optional, default: 300)
The amount of time for Elastic Load Balancing to wait before deregistering a target.
The range is 0-3600 seconds.
enableAnomalyMitigation?
Type:
boolean
(optional, default: false)
Indicates whether anomaly mitigation is enabled.
Only available when loadBalancingAlgorithmType is TargetGroupLoadBalancingAlgorithmType.WEIGHTED_RANDOM
healthCheck?
Type:
Health
(optional, default: The default value for each property in this configuration varies depending on the target.)
Health check configuration.
ipAddressType?
Type:
Target
(optional, default: undefined - ELB defaults to IPv4)
The type of IP addresses of the targets registered with the target group.
loadBalancingAlgorithmType?
Type:
Target
(optional, default: TargetGroupLoadBalancingAlgorithmType.ROUND_ROBIN)
The load balancing algorithm to select targets for routing requests.
multiValueHeadersEnabled?
Type:
boolean
(optional, default: false)
Indicates whether the target group supports multi-value headers.
If the value is true, the request and response headers exchanged between the load balancer and the Lambda function include arrays of values or strings.
Only applicable for Lambda targets.
port?
Type:
number
(optional, default: Determined from protocol if known)
The port on which the target receives traffic.
This is not applicable for Lambda targets.
protocol?
Type:
Application
(optional, default: Determined from port if known)
The protocol used for communication with the target.
This is not applicable for Lambda targets.
protocolVersion?
Type:
Application
(optional, default: ApplicationProtocolVersion.HTTP1)
The protocol version to use.
slowStart?
Type:
Duration
(optional, default: 0)
The time period during which the load balancer sends a newly registered target a linearly increasing share of the traffic to the target group.
The range is 30-900 seconds (15 minutes).
stickinessCookieDuration?
Type:
Duration
(optional, default: Stickiness is disabled)
The stickiness cookie expiration period.
Setting this value enables load balancer stickiness.
After this period, the cookie is considered stale. The minimum value is 1 second and the maximum value is 7 days (604800 seconds).
stickinessCookieName?
Type:
string
(optional, default: If stickinessCookieDuration is set, a load-balancer generated cookie is used. Otherwise, no stickiness is defined.)
The name of an application-based stickiness cookie.
Names that start with the following prefixes are not allowed: AWSALB, AWSALBAPP, and AWSALBTG; they're reserved for use by the load balancer.
Note: stickinessCookieName parameter depends on the presence of stickinessCookieDuration parameter.
If stickinessCookieDuration is not set, stickinessCookieName will be omitted.
See also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/sticky-sessions.html
targetGroupHealth?
Type:
Target
(optional, default: use default configuration)
Configuring target group health.
targetGroupName?
Type:
string
(optional, default: Automatically generated.)
The name of the target group.
This name must be unique per region per account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and must not begin or end with a hyphen.
targetType?
Type:
Target
(optional, default: Determined automatically.)
The type of targets registered to this TargetGroup, either IP or Instance.
All targets registered into the group must be of this type. If you register targets to the TargetGroup in the CDK app, the TargetType is determined automatically.
targets?
Type:
IApplication[]
(optional, default: No targets.)
The targets to add to this target group.
Can be Instance, IPAddress, or any self-registering load balancing
target. If you use either Instance or IPAddress as targets, all
target must be of the same type.
vpc?
Type:
IVpc
(optional, default: undefined)
The virtual private cloud (VPC).
only if TargetType is Ip or InstanceId
Properties
| Name | Type | Description |
|---|---|---|
| first | string | Full name of first load balancer. |
| health | Health | Health check for the members of this target group. |
| load | string | A token representing a list of ARNs of the load balancers that route traffic to this target group. |
| load | IDependable | List of constructs that need to be depended on to ensure the TargetGroup is associated to a load balancer. |
| metrics | IApplication | All metrics available for this target group. |
| node | Node | The tree node. |
| target | string | The ARN of the target group. |
| target | string | The full name of the target group. |
| target | string[] | ARNs of load balancers load balancing to this TargetGroup. |
| target | string | The name of the target group. |
| static PROPERTY_INJECTION_ID | string | Uniquely identifies this class. |
firstLoadBalancerFullName
Type:
string
Full name of first load balancer.
healthCheck
Type:
Health
Health check for the members of this target group.
loadBalancerArns
Type:
string
A token representing a list of ARNs of the load balancers that route traffic to this target group.
loadBalancerAttached
Type:
IDependable
List of constructs that need to be depended on to ensure the TargetGroup is associated to a load balancer.
metrics
Type:
IApplication
All metrics available for this target group.
node
Type:
Node
The tree node.
targetGroupArn
Type:
string
The ARN of the target group.
targetGroupFullName
Type:
string
The full name of the target group.
targetGroupLoadBalancerArns
Type:
string[]
ARNs of load balancers load balancing to this TargetGroup.
targetGroupName
Type:
string
The name of the target group.
static PROPERTY_INJECTION_ID
Type:
string
Uniquely identifies this class.
Methods
| Name | Description |
|---|---|
| add | Add a load balancing target to this target group. |
| configure | Set/replace the target group's health check. |
| enable | Enable sticky routing via a cookie to members of this target group. |
| metric(metricName, props?) | Return the given named metric for this Application Load Balancer Target Group. |
| metric | The number of healthy hosts in the target group. |
| metric | The number of HTTP 2xx/3xx/4xx/5xx response codes generated by all targets in this target group. |
| metric | The number of IPv6 requests received by the target group. |
| metric | The number of requests processed over IPv4 and IPv6. |
| metric | The average number of requests received by each target in a target group. |
| metric | The number of connections that were not successfully established between the load balancer and target. |
| metric | The time elapsed, in seconds, after the request leaves the load balancer until a response from the target is received. |
| metric | The number of TLS connections initiated by the load balancer that did not establish a session with the target. |
| metric | The number of unhealthy hosts in the target group. |
| register | Register a connectable as a member of this target group. |
| register | Register a listener that is load balancing to this target group. |
| set | Set a non-standard attribute on the target group. |
| to | Returns a string representation of this construct. |
| protected validate | |
| static from | Import an existing target group. |
addTarget(...targets)
public addTarget(...targets: IApplicationLoadBalancerTarget[]): void
Parameters
- targets
IApplicationLoad Balancer Target
Add a load balancing target to this target group.
configureHealthCheck(healthCheck)
public configureHealthCheck(healthCheck: HealthCheck): void
Parameters
- healthCheck
HealthCheck
Set/replace the target group's health check.
enableCookieStickiness(duration, cookieName?)
public enableCookieStickiness(duration: Duration, cookieName?: string): void
Parameters
- duration
Duration - cookieName
string
Enable sticky routing via a cookie to members of this target group.
Note: If the cookieName parameter is set, application-based stickiness will be applied,
otherwise it defaults to duration-based stickiness attributes (lb_cookie).
See also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/sticky-sessions.html
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string - props
MetricOptions
Returns
Return the given named metric for this Application Load Balancer Target Group.
Returns the metric for this target group from the point of view of the first load balancer load balancing to it. If you have multiple load balancers load sending traffic to the same target group, you will have to override the dimensions on this metric.
metricHealthyHostCount(props?)
public metricHealthyHostCount(props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.healthyHostCount instead
Parameters
- props
MetricOptions
Returns
The number of healthy hosts in the target group.
metricHttpCodeTarget(code, props?)
public metricHttpCodeTarget(code: HttpCodeTarget, props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.httpCodeTarget instead
Parameters
- code
HttpCode Target - props
MetricOptions
Returns
The number of HTTP 2xx/3xx/4xx/5xx response codes generated by all targets in this target group.
This does not include any response codes generated by the load balancer.
metricIpv6RequestCount(props?)
public metricIpv6RequestCount(props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.ipv6RequestCount instead
Parameters
- props
MetricOptions
Returns
The number of IPv6 requests received by the target group.
metricRequestCount(props?)
public metricRequestCount(props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.requestCount instead
Parameters
- props
MetricOptions
Returns
The number of requests processed over IPv4 and IPv6.
This count includes only the requests with a response generated by a target of the load balancer.
metricRequestCountPerTarget(props?)
public metricRequestCountPerTarget(props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.requestCountPerTarget instead
Parameters
- props
MetricOptions
Returns
The average number of requests received by each target in a target group.
The only valid statistic is Sum. Note that this represents the average not the sum.
metricTargetConnectionErrorCount(props?)
public metricTargetConnectionErrorCount(props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.targetConnectionErrorCount instead
Parameters
- props
MetricOptions
Returns
The number of connections that were not successfully established between the load balancer and target.
metricTargetResponseTime(props?)
public metricTargetResponseTime(props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.targetResponseTime instead
Parameters
- props
MetricOptions
Returns
The time elapsed, in seconds, after the request leaves the load balancer until a response from the target is received.
metricTargetTLSNegotiationErrorCount(props?)
public metricTargetTLSNegotiationErrorCount(props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.tlsNegotiationErrorCount instead
Parameters
- props
MetricOptions
Returns
The number of TLS connections initiated by the load balancer that did not establish a session with the target.
Possible causes include a mismatch of ciphers or protocols.
metricUnhealthyHostCount(props?)
public metricUnhealthyHostCount(props?: MetricOptions): Metric
⚠️ Deprecated: Use ApplicationTargetGroup.metrics.unhealthyHostCount instead
Parameters
- props
MetricOptions
Returns
The number of unhealthy hosts in the target group.
registerConnectable(connectable, portRange?)
public registerConnectable(connectable: IConnectable, portRange?: Port): void
Parameters
- connectable
IConnectable - portRange
Port
Register a connectable as a member of this target group.
Don't call this directly. It will be called by load balancing targets.
registerListener(listener, associatingConstruct?)
public registerListener(listener: IApplicationListener, associatingConstruct?: IConstruct): void
Parameters
- listener
IApplicationListener - associatingConstruct
IConstruct
Register a listener that is load balancing to this target group.
Don't call this directly. It will be called by listeners.
setAttribute(key, value?)
public setAttribute(key: string, value?: string): void
Parameters
- key
string - value
string
Set a non-standard attribute on the target group.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
protected validateTargetGroup()
protected validateTargetGroup(): string[]
Returns
string[]
static fromTargetGroupAttributes(scope, id, attrs)
public static fromTargetGroupAttributes(scope: Construct, id: string, attrs: TargetGroupAttributes): IApplicationTargetGroup
Parameters
- scope
Construct - id
string - attrs
TargetGroup Attributes
Returns
Import an existing target group.

.NET
Go
Java
Python
TypeScript (