aws-cdk-lib.aws_elasticloadbalancingv2.NetworkLoadBalancer

class NetworkLoadBalancer (construct)

LanguageType name
.NETAmazon.CDK.AWS.ElasticLoadBalancingV2.NetworkLoadBalancer
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awselasticloadbalancingv2#NetworkLoadBalancer
Javasoftware.amazon.awscdk.services.elasticloadbalancingv2.NetworkLoadBalancer
Pythonaws_cdk.aws_elasticloadbalancingv2.NetworkLoadBalancer
TypeScript (source)aws-cdk-lib » aws_elasticloadbalancingv2 » NetworkLoadBalancer

Implements IConstruct, IDependable, IResource, INetworkLoadBalancer, ILoadBalancerV2, IVpcEndpointServiceLoadBalancer

Define a new network load balancer.

Example

import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';

const vpc = new ec2.Vpc(this, 'VPC');
const nlb = new elbv2.NetworkLoadBalancer(this, 'NLB', {
  vpc,
});
const link = new apigateway.VpcLink(this, 'link', {
  targets: [nlb],
});

const integration = new apigateway.Integration({
  type: apigateway.IntegrationType.HTTP_PROXY,
  options: {
    connectionType: apigateway.ConnectionType.VPC_LINK,
    vpcLink: link,
  },
});

Initializer

new NetworkLoadBalancer(scope: Construct, id: string, props: NetworkLoadBalancerProps)

Parameters

  • scope Construct
  • id string
  • props NetworkLoadBalancerProps

Construct Props

NameTypeDescription
vpcIVpcThe VPC network to place the load balancer in.
crossZoneEnabled?booleanIndicates whether cross-zone load balancing is enabled.
deletionProtection?booleanIndicates whether deletion protection is enabled.
internetFacing?booleanWhether the load balancer has an internet-routable address.
loadBalancerName?stringName of the load balancer.
vpcSubnets?SubnetSelectionWhich subnets place the load balancer in.

vpc

Type: IVpc

The VPC network to place the load balancer in.


crossZoneEnabled?

Type: boolean (optional, default: false)

Indicates whether cross-zone load balancing is enabled.


deletionProtection?

Type: boolean (optional, default: false)

Indicates whether deletion protection is enabled.


internetFacing?

Type: boolean (optional, default: false)

Whether the load balancer has an internet-routable address.


loadBalancerName?

Type: string (optional, default: Automatically generated name.)

Name of the load balancer.


vpcSubnets?

Type: SubnetSelection (optional, default: the Vpc default strategy.)

Which subnets place the load balancer in.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
loadBalancerArnstringThe ARN of this load balancer.
loadBalancerCanonicalHostedZoneIdstringThe canonical hosted zone ID of this load balancer.
loadBalancerDnsNamestringThe DNS name of this load balancer.
loadBalancerFullNamestringThe full name of this load balancer.
loadBalancerNamestringThe name of this load balancer.
loadBalancerSecurityGroupsstring[]
metricsINetworkLoadBalancerMetricsAll metrics available for this load balancer.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.
vpc?IVpcThe VPC this load balancer has been created in.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


loadBalancerArn

Type: string

The ARN of this load balancer.

Example value: arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-internal-load-balancer/50dc6c495c0c9188


loadBalancerCanonicalHostedZoneId

Type: string

The canonical hosted zone ID of this load balancer.

Example value: Z2P70J7EXAMPLE


loadBalancerDnsName

Type: string

The DNS name of this load balancer.

Example value: my-load-balancer-424835706.us-west-2.elb.amazonaws.com


loadBalancerFullName

Type: string

The full name of this load balancer.

Example value: app/my-load-balancer/50dc6c495c0c9188


loadBalancerName

Type: string

The name of this load balancer.

Example value: my-load-balancer


loadBalancerSecurityGroups

Type: string[]


metrics

Type: INetworkLoadBalancerMetrics

All metrics available for this load balancer.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.


vpc?

Type: IVpc (optional)

The VPC this load balancer has been created in.

This property is always defined (not null or undefined) for sub-classes of BaseLoadBalancer.

Methods

NameDescription
addListener(id, props)Add a listener to this load balancer.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
logAccessLogs(bucket, prefix?)Enable access logging for this load balancer.
metric(metricName, props?)⚠️Return the given named metric for this Network Load Balancer.
metricActiveFlowCount(props?)⚠️The total number of concurrent TCP flows (or connections) from clients to targets.
metricConsumedLCUs(props?)⚠️The number of load balancer capacity units (LCU) used by your load balancer.
metricNewFlowCount(props?)⚠️The total number of new TCP flows (or connections) established from clients to targets in the time period.
metricProcessedBytes(props?)⚠️The total number of bytes processed by the load balancer, including TCP/IP headers.
metricTcpClientResetCount(props?)⚠️The total number of reset (RST) packets sent from a client to a target.
metricTcpElbResetCount(props?)⚠️The total number of reset (RST) packets generated by the load balancer.
metricTcpTargetResetCount(props?)⚠️The total number of reset (RST) packets sent from a target to a client.
removeAttribute(key)Remove an attribute from the load balancer.
setAttribute(key, value?)Set a non-standard attribute on the load balancer.
toString()Returns a string representation of this construct.
static fromLookup(scope, id, options)Looks up the network load balancer.
static fromNetworkLoadBalancerAttributes(scope, id, attrs)

addListener(id, props)

public addListener(id: string, props: BaseNetworkListenerProps): NetworkListener

Parameters

  • id string
  • props BaseNetworkListenerProps

Returns

  • NetworkListener

Add a listener to this load balancer.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


logAccessLogs(bucket, prefix?)

public logAccessLogs(bucket: IBucket, prefix?: string): void

Parameters

  • bucket IBucket
  • prefix string

Enable access logging for this load balancer.

A region must be specified on the stack containing the load balancer; you cannot enable logging on environment-agnostic stacks. See https://docs.aws.amazon.com/cdk/latest/guide/environments.html


metric(metricName, props?)⚠️

public metric(metricName: string, props?: MetricOptions): Metric

⚠️ Deprecated: Use NetworkLoadBalancer.metrics.custom instead

Parameters

  • metricName string
  • props MetricOptions

Returns

  • Metric

Return the given named metric for this Network Load Balancer.


metricActiveFlowCount(props?)⚠️

public metricActiveFlowCount(props?: MetricOptions): Metric

⚠️ Deprecated: Use NetworkLoadBalancer.metrics.activeFlowCount instead

Parameters

  • props MetricOptions

Returns

  • Metric

The total number of concurrent TCP flows (or connections) from clients to targets.

This metric includes connections in the SYN_SENT and ESTABLISHED states. TCP connections are not terminated at the load balancer, so a client opening a TCP connection to a target counts as a single flow.


metricConsumedLCUs(props?)⚠️

public metricConsumedLCUs(props?: MetricOptions): Metric

⚠️ Deprecated: Use NetworkLoadBalancer.metrics.activeFlowCount instead

Parameters

  • props MetricOptions

Returns

  • Metric

The number of load balancer capacity units (LCU) used by your load balancer.


metricNewFlowCount(props?)⚠️

public metricNewFlowCount(props?: MetricOptions): Metric

⚠️ Deprecated: Use NetworkLoadBalancer.metrics.newFlowCount instead

Parameters

  • props MetricOptions

Returns

  • Metric

The total number of new TCP flows (or connections) established from clients to targets in the time period.


metricProcessedBytes(props?)⚠️

public metricProcessedBytes(props?: MetricOptions): Metric

⚠️ Deprecated: Use NetworkLoadBalancer.metrics.processedBytes instead

Parameters

  • props MetricOptions

Returns

  • Metric

The total number of bytes processed by the load balancer, including TCP/IP headers.


metricTcpClientResetCount(props?)⚠️

public metricTcpClientResetCount(props?: MetricOptions): Metric

⚠️ Deprecated: Use NetworkLoadBalancer.metrics.tcpClientResetCount instead

Parameters

  • props MetricOptions

Returns

  • Metric

The total number of reset (RST) packets sent from a client to a target.

These resets are generated by the client and forwarded by the load balancer.


metricTcpElbResetCount(props?)⚠️

public metricTcpElbResetCount(props?: MetricOptions): Metric

⚠️ Deprecated: Use NetworkLoadBalancer.metrics.tcpElbResetCount instead

Parameters

  • props MetricOptions

Returns

  • Metric

The total number of reset (RST) packets generated by the load balancer.


metricTcpTargetResetCount(props?)⚠️

public metricTcpTargetResetCount(props?: MetricOptions): Metric

⚠️ Deprecated: Use NetworkLoadBalancer.metrics.tcpTargetResetCount instead

Parameters

  • props MetricOptions

Returns

  • Metric

The total number of reset (RST) packets sent from a target to a client.

These resets are generated by the target and forwarded by the load balancer.


removeAttribute(key)

public removeAttribute(key: string): void

Parameters

  • key string

Remove an attribute from the load balancer.


setAttribute(key, value?)

public setAttribute(key: string, value?: string): void

Parameters

  • key string
  • value string

Set a non-standard attribute on the load balancer.

See also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#load-balancer-attributes


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromLookup(scope, id, options)

public static fromLookup(scope: Construct, id: string, options: NetworkLoadBalancerLookupOptions): INetworkLoadBalancer

Parameters

  • scope Construct
  • id string
  • options NetworkLoadBalancerLookupOptions

Returns

  • INetworkLoadBalancer

Looks up the network load balancer.


static fromNetworkLoadBalancerAttributes(scope, id, attrs)

public static fromNetworkLoadBalancerAttributes(scope: Construct, id: string, attrs: NetworkLoadBalancerAttributes): INetworkLoadBalancer

Parameters

  • scope Construct
  • id string
  • attrs NetworkLoadBalancerAttributes

Returns

  • INetworkLoadBalancer