class NetworkLoadBalancer (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ElasticLoadBalancingV2.NetworkLoadBalancer |
Java | software.amazon.awscdk.services.elasticloadbalancingv2.NetworkLoadBalancer |
Python | aws_cdk.aws_elasticloadbalancingv2.NetworkLoadBalancer |
TypeScript (source) | @aws-cdk/aws-elasticloadbalancingv2 » NetworkLoadBalancer |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, INetwork
, ILoad
, IVpc
Define a new network load balancer.
Example
import { HttpNlbIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
const vpc = new ec2.Vpc(this, 'VPC');
const lb = new elbv2.NetworkLoadBalancer(this, 'lb', { vpc });
const listener = lb.addListener('listener', { port: 80 });
listener.addTargets('target', {
port: 80,
});
const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', {
defaultIntegration: new HttpNlbIntegration('DefaultIntegration', listener),
});
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. |
cross | boolean | Indicates whether cross-zone load balancing is enabled. |
deletion | boolean | Indicates whether deletion protection is enabled. |
internet | boolean | Whether the load balancer has an internet-routable address. |
load | string | Name of the load balancer. |
vpc | Subnet | Which 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:
Subnet
(optional, default: the Vpc default strategy.)
Which subnets place the load balancer in.
Properties
Name | Type | Description |
---|---|---|
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[] | |
node | Construct | The construct tree node associated with this construct. |
stack | Stack | The stack in which this resource is defined. |
vpc? | IVpc | The VPC this load balancer has been created in. |
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[]
node
Type:
Construct
The construct tree node associated with this construct.
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
Name | Description |
---|---|
add | Add a listener 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 number of targets that are considered healthy. |
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. |
metric | The number of targets that are considered unhealthy. |
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.
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
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this Network Load Balancer.
metricActiveFlowCount(props?)
public metricActiveFlowCount(props?: MetricOptions): Metric
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
Parameters
- props
Metric
Options
Returns
The number of load balancer capacity units (LCU) used by your load balancer.
metricHealthyHostCount(props?)
public metricHealthyHostCount(props?: MetricOptions): Metric
⚠️ Deprecated: use NetworkTargetGroup.metricHealthyHostCount
instead
Parameters
- props
Metric
Options
Returns
The number of targets that are considered healthy.
metricNewFlowCount(props?)
public metricNewFlowCount(props?: MetricOptions): Metric
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
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
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
Parameters
- props
Metric
Options
Returns
The total number of reset (RST) packets generated by the load balancer.
metricTcpTargetResetCount(props?)
public metricTcpTargetResetCount(props?: MetricOptions): Metric
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.
metricUnHealthyHostCount(props?)
public metricUnHealthyHostCount(props?: MetricOptions): Metric
⚠️ Deprecated: use NetworkTargetGroup.metricUnHealthyHostCount
instead
Parameters
- props
Metric
Options
Returns
The number of targets that are considered unhealthy.
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