class NetworkLoadBalancer (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.ElasticLoadBalancingV2.NetworkLoadBalancer |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awselasticloadbalancingv2#NetworkLoadBalancer |
![]() | software.amazon.awscdk.services.elasticloadbalancingv2.NetworkLoadBalancer |
![]() | aws_cdk.aws_elasticloadbalancingv2.NetworkLoadBalancer |
![]() | aws-cdk-lib » aws_elasticloadbalancingv2 » NetworkLoadBalancer |
Implements
IConstruct
, IDependable
, IResource
, INetwork
, ILoad
, IVpc
, IConnectable
Define a new network load balancer.
Example
declare const vpc: ec2.Vpc;
const lb = new elbv2.NetworkLoadBalancer(this, 'LB', {
vpc,
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
enablePrefixForIpv6SourceNat: true,
});
const listener = lb.addListener('Listener', {
port: 1229,
protocol: elbv2.Protocol.UDP,
});
Initializer
new NetworkLoadBalancer(scope: Construct, id: string, props: NetworkLoadBalancerProps)
Parameters
- scope
Construct
- id
string
- props
Network
Load Balancer Props
Construct Props
Name | Type | Description |
---|---|---|
vpc | IVpc | The VPC network to place the load balancer in. |
client | Client | The AZ affinity routing policy. |
cross | boolean | Indicates whether cross-zone load balancing is enabled. |
deletion | boolean | Indicates whether deletion protection is enabled. |
deny | boolean | Indicates whether the load balancer blocks traffic through the Internet Gateway (IGW). |
enable | boolean | Indicates whether to use an IPv6 prefix from each subnet for source NAT. |
enforce | boolean | Indicates whether to evaluate inbound security group rules for traffic sent to a Network Load Balancer through AWS PrivateLink. |
internet | boolean | Whether the load balancer has an internet-routable address. |
ip | Ip | The type of IP addresses to use. |
load | string | Name of the load balancer. |
minimum | number | The minimum capacity (LCU) for a load balancer. |
security | ISecurity [] | Security groups to associate with this load balancer. |
vpc | Subnet | Which subnets place the load balancer in. |
zonal | boolean | Indicates whether zonal shift is enabled. |
vpc
Type:
IVpc
The VPC network to place the load balancer in.
clientRoutingPolicy?
Type:
Client
(optional, default: AZ affinity is disabled.)
The AZ affinity routing policy.
crossZoneEnabled?
Type:
boolean
(optional, default: false for Network Load Balancers and true for Application Load Balancers.
This can not be false
for Application Load Balancers.)
Indicates whether cross-zone load balancing is enabled.
deletionProtection?
Type:
boolean
(optional, default: false)
Indicates whether deletion protection is enabled.
denyAllIgwTraffic?
Type:
boolean
(optional, default: false for internet-facing load balancers and true for internal load balancers)
Indicates whether the load balancer blocks traffic through the Internet Gateway (IGW).
enablePrefixForIpv6SourceNat?
Type:
boolean
(optional, default: undefined - NLB default behavior is false)
Indicates whether to use an IPv6 prefix from each subnet for source NAT.
The IP address type must be IpAddressType.DUALSTACK.
enforceSecurityGroupInboundRulesOnPrivateLinkTraffic?
Type:
boolean
(optional, default: true)
Indicates whether to evaluate inbound security group rules for traffic sent to a Network Load Balancer through AWS PrivateLink.
internetFacing?
Type:
boolean
(optional, default: false)
Whether the load balancer has an internet-routable address.
ipAddressType?
Type:
Ip
(optional, default: IpAddressType.IPV4)
The type of IP addresses to use.
If you want to add a UDP or TCP_UDP listener to the load balancer, you must choose IPv4.
loadBalancerName?
Type:
string
(optional, default: Automatically generated name.)
Name of the load balancer.
minimumCapacityUnit?
Type:
number
(optional, default: undefined - ELB default is 0 LCU)
The minimum capacity (LCU) for a load balancer.
See also: https://exampleloadbalancer.com/ondemand_capacity_reservation_calculator.html
securityGroups?
Type:
ISecurity
[]
(optional, default: No security groups associated with the load balancer.)
Security groups to associate with this load balancer.
vpcSubnets?
Type:
Subnet
(optional, default: the Vpc default strategy.)
Which subnets place the load balancer in.
zonalShift?
Type:
boolean
(optional, default: false)
Indicates whether zonal shift is enabled.
Properties
Name | Type | Description |
---|---|---|
connections | Connections | The network connections associated with this resource. |
env | Resource | The environment this resource belongs to. |
load | string | The ARN of this load balancer. |
load | string | The canonical hosted zone ID of this load balancer. |
load | string | The DNS name of this load balancer. |
load | string | The full name of this load balancer. |
load | string | The name of this load balancer. |
load | string[] | |
metrics | INetwork | All metrics available for this load balancer. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
enforce | string | Indicates whether to evaluate inbound security group rules for traffic sent to a Network Load Balancer through AWS PrivateLink. |
ip | Ip | The type of IP addresses to use. |
security | string[] | After the implementation of IConnectable (see https://github.com/aws/aws-cdk/pull/28494), the default value for securityGroups is set by the ec2.Connections constructor to an empty array. To keep backward compatibility (securityGroups is undefined if the related property is not specified) a getter has been added. |
vpc? | IVpc | The VPC this load balancer has been created in. |
connections
Type:
Connections
The network connections associated with this resource.
env
Type:
Resource
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:
INetwork
All metrics available for this load balancer.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
enforceSecurityGroupInboundRulesOnPrivateLinkTraffic?
Type:
string
(optional)
Indicates whether to evaluate inbound security group rules for traffic sent to a Network Load Balancer through AWS PrivateLink.
ipAddressType?
Type:
Ip
(optional)
The type of IP addresses to use.
securityGroups?
Type:
string[]
(optional)
After the implementation of IConnectable
(see https://github.com/aws/aws-cdk/pull/28494), the default value for securityGroups
is set by the ec2.Connections
constructor to an empty array. To keep backward compatibility (securityGroups
is undefined
if the related property is not specified) a getter has been added.
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
Name | Description |
---|---|
add | Add a listener to this load balancer. |
add | Add a security group to this load balancer. |
apply | Apply the given removal policy to this resource. |
log | Enable access logging for this load balancer. |
metric(metricName, props?) | Return the given named metric for this Network Load Balancer. |
metric | The total number of concurrent TCP flows (or connections) from clients to targets. |
metric | The number of load balancer capacity units (LCU) used by your load balancer. |
metric | The total number of new TCP flows (or connections) established from clients to targets in the time period. |
metric | The total number of bytes processed by the load balancer, including TCP/IP headers. |
metric | The total number of reset (RST) packets sent from a client to a target. |
metric | The total number of reset (RST) packets generated by the load balancer. |
metric | The total number of reset (RST) packets sent from a target to a client. |
remove | Remove an attribute from the load balancer. |
set | Set a non-standard attribute on the load balancer. |
to | Returns a string representation of this construct. |
static from | Looks up the network load balancer. |
static from |
addListener(id, props)
public addListener(id: string, props: BaseNetworkListenerProps): NetworkListener
Parameters
- id
string
- props
Base
Network Listener Props
Returns
Add a listener to this load balancer.
addSecurityGroup(securityGroup)
public addSecurityGroup(securityGroup: ISecurityGroup): void
Parameters
- securityGroup
ISecurity
Group
Add a security group to this load balancer.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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.
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
Network
Load Balancer Lookup Options
Returns
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
Network
Load Balancer Attributes
Returns