Skip to content
v2.275.0

NetworkTargetGroup ​

Define a Network Target Group.

Example ​

ts
import * as elb from 'aws-cdk-lib/aws-elasticloadbalancing';
import * as elb2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';

declare const clb: elb.LoadBalancer;
declare const alb: elb2.ApplicationLoadBalancer;
declare const nlb: elb2.NetworkLoadBalancer;

const albListener = alb.addListener('ALBListener', { port: 80 });
const albTargetGroup = albListener.addTargets('ALBFleet', { port: 80 });

const nlbListener = nlb.addListener('NLBListener', { port: 80 });
const nlbTargetGroup = nlbListener.addTargets('NLBFleet', { port: 80 });

const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'DeploymentGroup', {
  loadBalancers: [
    codedeploy.LoadBalancer.classic(clb),
    codedeploy.LoadBalancer.application(albTargetGroup),
    codedeploy.LoadBalancer.network(nlbTargetGroup),
  ]
});
python
import aws_cdk.aws_elasticloadbalancing as elb
import aws_cdk.aws_elasticloadbalancingv2 as elb2

# clb: elb.LoadBalancer
# alb: elb2.ApplicationLoadBalancer
# nlb: elb2.NetworkLoadBalancer


alb_listener = alb.add_listener("ALBListener", port=80)
alb_target_group = alb_listener.add_targets("ALBFleet", port=80)

nlb_listener = nlb.add_listener("NLBListener", port=80)
nlb_target_group = nlb_listener.add_targets("NLBFleet", port=80)

deployment_group = codedeploy.ServerDeploymentGroup(self, "DeploymentGroup",
    load_balancers=[
        codedeploy.LoadBalancer.classic(clb),
        codedeploy.LoadBalancer.application(alb_target_group),
        codedeploy.LoadBalancer.network(nlb_target_group)
    ]
)
java
import software.amazon.awscdk.services.elasticloadbalancing.*;
import software.amazon.awscdk.services.elasticloadbalancingv2.*;

LoadBalancer clb;
ApplicationLoadBalancer alb;
NetworkLoadBalancer nlb;


ApplicationListener albListener = alb.addListener("ALBListener", BaseApplicationListenerProps.builder().port(80).build());
ApplicationTargetGroup albTargetGroup = albListener.addTargets("ALBFleet", AddApplicationTargetsProps.builder().port(80).build());

NetworkListener nlbListener = nlb.addListener("NLBListener", BaseNetworkListenerProps.builder().port(80).build());
NetworkTargetGroup nlbTargetGroup = nlbListener.addTargets("NLBFleet", AddNetworkTargetsProps.builder().port(80).build());

ServerDeploymentGroup deploymentGroup = ServerDeploymentGroup.Builder.create(this, "DeploymentGroup")
        .loadBalancers(List.of(LoadBalancer.classic(clb), LoadBalancer.application(albTargetGroup), LoadBalancer.network(nlbTargetGroup)))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.ElasticLoadBalancing;
using Amazon.CDK.AWS.ElasticLoadBalancingV2;

LoadBalancer clb;
ApplicationLoadBalancer alb;
NetworkLoadBalancer nlb;


var albListener = alb.AddListener("ALBListener", new BaseApplicationListenerProps { Port = 80 });
var albTargetGroup = albListener.AddTargets("ALBFleet", new AddApplicationTargetsProps { Port = 80 });

var nlbListener = nlb.AddListener("NLBListener", new BaseNetworkListenerProps { Port = 80 });
var nlbTargetGroup = nlbListener.AddTargets("NLBFleet", new AddNetworkTargetsProps { Port = 80 });

var deploymentGroup = new ServerDeploymentGroup(this, "DeploymentGroup", new ServerDeploymentGroupProps {
    LoadBalancers = new [] { LoadBalancer.Classic(clb), LoadBalancer.Application(albTargetGroup), LoadBalancer.Network(nlbTargetGroup) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import elb "github.com/aws/aws-cdk-go/awscdk"
import elb2 "github.com/aws/aws-cdk-go/awscdk"

var clb LoadBalancer
var alb ApplicationLoadBalancer
var nlb NetworkLoadBalancer


albListener := alb.AddListener(jsii.String("ALBListener"), &BaseApplicationListenerProps{
	Port: jsii.Number(80),
})
albTargetGroup := albListener.AddTargets(jsii.String("ALBFleet"), &AddApplicationTargetsProps{
	Port: jsii.Number(80),
})

nlbListener := nlb.AddListener(jsii.String("NLBListener"), &BaseNetworkListenerProps{
	Port: jsii.Number(80),
})
nlbTargetGroup := nlbListener.AddTargets(jsii.String("NLBFleet"), &AddNetworkTargetsProps{
	Port: jsii.Number(80),
})

deploymentGroup := codedeploy.NewServerDeploymentGroup(this, jsii.String("DeploymentGroup"), &ServerDeploymentGroupProps{
	LoadBalancers: []LoadBalancer{
		codedeploy.LoadBalancer_Classic(clb),
		codedeploy.LoadBalancer_Application(albTargetGroup),
		codedeploy.LoadBalancer_Network(nlbTargetGroup),
	},
})

Initializer ​

ts
new NetworkTargetGroup(scope: Construct, id: string, props: NetworkTargetGroupProps)
python
NetworkTargetGroup(scope: Construct, id: str, props: NetworkTargetGroupProps)
java
new NetworkTargetGroup(Construct scope, String id, NetworkTargetGroupProps props)
csharp
new NetworkTargetGroup(Construct scope, string id, NetworkTargetGroupProps props)
go
NewNetworkTargetGroup(Scope Construct, Id *string, Props NetworkTargetGroupProps)

Construct Props ​

connectionTerminationoptionalbooleanconnection_terminationoptionalboolconnectionTerminationoptionalBooleanConnectionTerminationoptionalboolConnectionTerminationoptional*bool= false#
Indicates whether the load balancer terminates connections at the end of the deregistration timeout.
crossZoneEnabledoptionalbooleancross_zone_enabledoptionalboolcrossZoneEnabledoptionalBooleanCrossZoneEnabledoptionalboolCrossZoneEnabledoptional*bool#
Indicates whether cross zone load balancing is enabled.

Default: use load balancer configuration

deregistrationDelayoptionalDurationderegistration_delayoptionalDurationderegistrationDelayoptionalDurationDeregistrationDelayoptionalDurationDeregistrationDelayoptionalDuration= 300#
The amount of time for Elastic Load Balancing to wait before deregistering a target.

The range is 0-3600 seconds.

healthCheckoptionalHealthCheckhealth_checkoptionalHealthCheckhealthCheckoptionalHealthCheckHealthCheckoptionalHealthCheckHealthCheckoptionalHealthCheck#
Health check configuration.

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

ipAddressTypeoptionalTargetGroupIpAddressTypeip_address_typeoptionalTargetGroupIpAddressTypeipAddressTypeoptionalTargetGroupIpAddressTypeIpAddressTypeoptionalTargetGroupIpAddressTypeIpAddressTypeoptionalTargetGroupIpAddressType#
The type of IP addresses of the targets registered with the target group.

Default: undefined - ELB defaults to IPv4

portnumberportint | floatportNumberPortdoublePort*float64required#
The port on which the target receives traffic.
preserveClientIpoptionalbooleanpreserve_client_ipoptionalboolpreserveClientIpoptionalBooleanPreserveClientIpoptionalboolPreserveClientIpoptional*bool#
Indicates whether client IP preservation is enabled.

Default: false if the target group type is IP address and the target group protocol is TCP or TLS. Otherwise, true.

protocoloptionalProtocolprotocoloptionalProtocolprotocoloptionalProtocolProtocoloptionalProtocolProtocoloptionalProtocol= TCP#
Protocol for target group, expects TCP, TLS, UDP, or TCP_UDP.
proxyProtocolV2optionalbooleanproxy_protocol_v2optionalboolproxyProtocolV2optionalBooleanProxyProtocolV2optionalboolProxyProtocolV2optional*bool= false#
Indicates whether Proxy Protocol version 2 is enabled.
targetGroupHealthoptionalTargetGroupHealthtarget_group_healthoptionalTargetGroupHealthtargetGroupHealthoptionalTargetGroupHealthTargetGroupHealthoptionalTargetGroupHealthTargetGroupHealthoptionalTargetGroupHealth#
Configuring target group health.

Default: use default configuration

targetGroupNameoptionalstringtarget_group_nameoptionalstrtargetGroupNameoptionalStringTargetGroupNameoptionalstringTargetGroupNameoptional*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.

targetsoptionalINetworkLoadBalancerTarget[]targetsoptionaltyping.List[INetworkLoadBalancerTarget]targetsoptionalList<INetworkLoadBalancerTarget>TargetsoptionalINetworkLoadBalancerTarget[]Targetsoptional*[]INetworkLoadBalancerTarget#
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.

targetTypeoptionalTargetTypetarget_typeoptionalTargetTypetargetTypeoptionalTargetTypeTargetTypeoptionalTargetTypeTargetTypeoptionalTargetType#
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.

vpcoptionalIVpcvpcoptionalIVpcvpcoptionalIVpcVpcoptionalIVpcVpcoptionalIVpc= undefined#
The virtual private cloud (VPC).

only if TargetType is Ip or InstanceId

Properties ​

firstLoadBalancerFullNamestringfirst_load_balancer_full_namestrfirstLoadBalancerFullNameStringFirstLoadBalancerFullNamestringFirstLoadBalancerFullName*string#
Full name of first load balancer.
healthCheckHealthCheckhealth_checkHealthCheckhealthCheckHealthCheckHealthCheckHealthCheckHealthCheckHealthCheck#
Health check for the members of this target group.
isNetworkTargetGroupbooleanis_network_target_groupboolisNetworkTargetGroupBooleanIsNetworkTargetGroupboolIsNetworkTargetGroup*bool#
Indicates that this is a Network Target Group.

Will always return true, but is necessary to prevent accidental structural equality in TypeScript.

loadBalancerArnsstringload_balancer_arnsstrloadBalancerArnsStringLoadBalancerArnsstringLoadBalancerArns*string#
A token representing a list of ARNs of the load balancers that route traffic to this target group.
loadBalancerAttachedIDependableload_balancer_attachedIDependableloadBalancerAttachedIDependableLoadBalancerAttachedIDependableLoadBalancerAttachedIDependable#
List of constructs that need to be depended on to ensure the TargetGroup is associated to a load balancer.
nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#
Uniquely identifies this class.
targetGroupArnstringtarget_group_arnstrtargetGroupArnStringTargetGroupArnstringTargetGroupArn*string#
The ARN of the target group.
targetGroupFullNamestringtarget_group_full_namestrtargetGroupFullNameStringTargetGroupFullNamestringTargetGroupFullName*string#
The full name of the target group.
targetGroupLoadBalancerArnsstring[]target_group_load_balancer_arnstyping.List[str]targetGroupLoadBalancerArnsList<String>TargetGroupLoadBalancerArnsstring[]TargetGroupLoadBalancerArns*[]*string#
ARNs of load balancers load balancing to this TargetGroup.
targetGroupNamestringtarget_group_namestrtargetGroupNameStringTargetGroupNamestringTargetGroupName*string#
The name of the target group.
targetGroupRefTargetGroupReferencetarget_group_refTargetGroupReferencetargetGroupRefTargetGroupReferenceTargetGroupRefTargetGroupReferenceTargetGroupRefTargetGroupReference#
A reference to this target group.

Methods ​

addTarget(...targets: INetworkLoadBalancerTarget[]): voiddef add_target(self, targets: INetworkLoadBalancerTarget) -> Nonepublic void addTarget(INetworkLoadBalancerTarget targets)public void AddTarget(INetworkLoadBalancerTarget targets)func AddTarget(Targets INetworkLoadBalancerTarget)#
Add a load balancing target to this target group.
configureHealthCheck(healthCheck: HealthCheck): voiddef configure_health_check(self, health_check: HealthCheck) -> Nonepublic void configureHealthCheck(HealthCheck healthCheck)public void ConfigureHealthCheck(HealthCheck healthCheck)func ConfigureHealthCheck(HealthCheck HealthCheck)#
Set/replace the target group's health check.
fromTargetGroupAttributes(scope: Construct, id: string, attrs: TargetGroupAttributes): INetworkTargetGroup@staticmethod def from_target_group_attributes(scope: Construct, id: str, attrs: TargetGroupAttributes) -> INetworkTargetGrouppublic static INetworkTargetGroup fromTargetGroupAttributes(Construct scope, String id, TargetGroupAttributes attrs)public static INetworkTargetGroup FromTargetGroupAttributes(Construct scope, string id, TargetGroupAttributes attrs)func FromTargetGroupAttributes(Scope Construct, Id *string, Attrs TargetGroupAttributes) INetworkTargetGroupstatic#
Import an existing target group.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

metricHealthyHostCount(props?: MetricOptions): Metricdef metric_healthy_host_count(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricHealthyHostCount(MetricOptions props)public Metric MetricHealthyHostCount(MetricOptions? props = null)func MetricHealthyHostCount(Props MetricOptions) Metricdeprecated#
Use ``NetworkTargetGroup.metrics.healthyHostCount`` instead
metricUnHealthyHostCount(props?: MetricOptions): Metricdef metric_un_healthy_host_count(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricUnHealthyHostCount(MetricOptions props)public Metric MetricUnHealthyHostCount(MetricOptions? props = null)func MetricUnHealthyHostCount(Props MetricOptions) Metricdeprecated#
Use ``NetworkTargetGroup.metrics.healthyHostCount`` instead
registerListener(listener: INetworkListenerRef): voiddef register_listener(self, listener: INetworkListenerRef) -> Nonepublic void registerListener(INetworkListenerRef listener)public void RegisterListener(INetworkListenerRef listener)func RegisterListener(Listener INetworkListenerRef)#
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): voiddef set_attribute(self, key: str, value: typing.Optional[str] = None) -> Nonepublic void setAttribute(String key, String value)public void SetAttribute(string key, string? value = null)func SetAttribute(Key *string, Value *string)#
Set a non-standard attribute on the target group.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining