# ApplicationTargetGroup

Define an Application Target Group.

Extends: Construct › TargetGroupBase › ApplicationTargetGroup
Implements: IApplicationTargetGroup, ITargetGroup, IEnvironmentAware, ITargetGroupRef, IConstruct, IDependable

- Source: [`aws-elasticloadbalancingv2/lib/alb/application-target-group.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts#L314)
- Type last changed: v2.196.0 · 16 May 2025

## Example

```ts
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

```ts
new ApplicationTargetGroup(scope: Construct, id: string, props?: ApplicationTargetGroupProps)
```

## Construct Props

- `crossZoneEnabled`: boolean — Indicates whether cross zone load balancing is enabled.

  **Default:** use load balancer configuration

- `deregistrationDelay`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = 300 — The amount of time for Elastic Load Balancing to wait before deregistering a target.

  The range is 0-3600 seconds.

- `enableAnomalyMitigation`: boolean = false — Indicates whether anomaly mitigation is enabled.

  Only available when `loadBalancingAlgorithmType` is `TargetGroupLoadBalancingAlgorithmType.WEIGHTED_RANDOM`

- `healthCheck`: [HealthCheck](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.HealthCheck.html) — Health check configuration.

  **Default:** The default value for each property in this configuration varies depending on the target.

- `ipAddressType`: [TargetGroupIpAddressType](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.TargetGroupIpAddressType.html) — The type of IP addresses of the targets registered with the target group.

  **Default:** undefined - ELB defaults to IPv4

- `loadBalancingAlgorithmType`: [TargetGroupLoadBalancingAlgorithmType](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.TargetGroupLoadBalancingAlgorithmType.html) — The load balancing algorithm to select targets for routing requests.

  **Default:** TargetGroupLoadBalancingAlgorithmType.ROUND_ROBIN

- `multiValueHeadersEnabled`: boolean = 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`: number — The port on which the target receives traffic.

  **Default:** Determined from protocol if known

  This is not applicable for Lambda targets.

- `protocol`: [ApplicationProtocol](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationProtocol.html) — The protocol used for communication with the target.

  **Default:** Determined from port if known

  This is not applicable for Lambda targets.

- `protocolVersion`: [ApplicationProtocolVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationProtocolVersion.html) = ApplicationProtocolVersion.HTTP1 — The protocol version to use.

- `slowStart`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = 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`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — The stickiness cookie expiration period.

  **Default:** Stickiness is disabled

  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`: string — The name of an application-based stickiness cookie.

  **Default:** If `stickinessCookieDuration` is set, a load-balancer generated cookie is used. Otherwise, no stickiness is defined.

  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.

- `targetGroupHealth`: [TargetGroupHealth](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.TargetGroupHealth.html) — Configuring target group health.

  **Default:** use default configuration

- `targetGroupName`: string — The name of the target group.

  **Default:** Automatically generated.

  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.

- `targets`: [IApplicationLoadBalancerTarget](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationLoadBalancerTarget.html)[] — The targets to add to this target group.

  **Default:** No targets.

  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.

- `targetType`: [TargetType](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.TargetType.html) — The type of targets registered to this TargetGroup, either IP or Instance.

  **Default:** Determined automatically.

  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.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) = undefined — The virtual private cloud (VPC).

  only if `TargetType` is `Ip` or `InstanceId`

## Properties

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

- `firstLoadBalancerFullName`: string — Full name of first load balancer.

- `healthCheck`: [HealthCheck](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.HealthCheck.html) — Health check for the members of this target group.

- `loadBalancerArns`: string — A token representing a list of ARNs of the load balancers that route traffic to this target group.

- `loadBalancerAttached`: [IDependable](/cdk/api/v2/docs/constructs.IDependable.html) — List of constructs that need to be depended on to ensure the TargetGroup is associated to a load balancer.

- `metrics`: [IApplicationTargetGroupMetrics](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationTargetGroupMetrics.html) — All metrics available for this target group.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `targetGroupArn`: string — The ARN of the target group.

- `targetGroupFullName`: string — The full name of the target group.

- `targetGroupLoadBalancerArns`: string[] — ARNs of load balancers load balancing to this TargetGroup.

- `targetGroupName`: string — The name of the target group.

- `targetGroupRef`: [TargetGroupReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_elasticloadbalancingv2.TargetGroupReference.html) — A reference to this target group.

## Methods

- `addTarget(...targets: IApplicationLoadBalancerTarget[]): void` — Add a load balancing target to this target group.

- `configureHealthCheck(healthCheck: HealthCheck): void` — Set/replace the target group's health check.

- `enableCookieStickiness(duration: Duration, cookieName?: string): void` — 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`).

- `fromTargetGroupAttributes(scope: Construct, id: string, attrs: TargetGroupAttributes): IApplicationTargetGroup` (static) — Import an existing target group.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `metric(metricName: string, props?: MetricOptions): Metric` — 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?: MetricOptions): Metric` — Use ``ApplicationTargetGroup.metrics.healthyHostCount`` instead

- `metricHttpCodeTarget(code: HttpCodeTarget, props?: MetricOptions): Metric` — Use ``ApplicationTargetGroup.metrics.httpCodeTarget`` instead

  This does not include any response codes generated by the load balancer.

- `metricIpv6RequestCount(props?: MetricOptions): Metric` — Use ``ApplicationTargetGroup.metrics.ipv6RequestCount`` instead

- `metricRequestCount(props?: MetricOptions): Metric` — Use ``ApplicationTargetGroup.metrics.requestCount`` instead

  This count includes only the requests with a response generated by a target of the load balancer.

- `metricRequestCountPerTarget(props?: MetricOptions): Metric` — Use `ApplicationTargetGroup.metrics.requestCountPerTarget` instead

  The only valid statistic is Sum. Note that this represents the average not the sum.

- `metricTargetConnectionErrorCount(props?: MetricOptions): Metric` — Use ``ApplicationTargetGroup.metrics.targetConnectionErrorCount`` instead

- `metricTargetResponseTime(props?: MetricOptions): Metric` — Use ``ApplicationTargetGroup.metrics.targetResponseTime`` instead

- `metricTargetTLSNegotiationErrorCount(props?: MetricOptions): Metric` — Use ``ApplicationTargetGroup.metrics.tlsNegotiationErrorCount`` instead

  Possible causes include a mismatch of ciphers or protocols.

- `metricUnhealthyHostCount(props?: MetricOptions): Metric` — Use ``ApplicationTargetGroup.metrics.unhealthyHostCount`` instead

- `registerConnectable(connectable: IConnectable, portRange?: Port): void` — 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: IApplicationListener, associatingConstruct?: IConstruct): void` — Register a listener that is load balancing to this target group.

  Don't call this directly. It will be called by listeners.

- `setAttribute(key: string, value?: string): void` — Set a non-standard attribute on the target group.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
