NetworkLoadBalancerAttributes Struct
Properties to reference an existing load balancer.
| Source | aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts |
|---|---|
| Type last changed |
Example
ts
// Create an Accelerator
const accelerator = new globalaccelerator.Accelerator(this, 'Accelerator');
// Create a Listener
const listener = accelerator.addListener('Listener', {
portRanges: [
{ fromPort: 80 },
{ fromPort: 443 },
],
});
// Import the Load Balancers
const nlb1 = elbv2.NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(this, 'NLB1', {
loadBalancerArn: 'arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b',
});
const nlb2 = elbv2.NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(this, 'NLB2', {
loadBalancerArn: 'arn:aws:elasticloadbalancing:ap-south-1:111111111111:loadbalancer/app/my-load-balancer2/5513dc2ea8a1',
});
// Add one EndpointGroup for each Region we are targeting
listener.addEndpointGroup('Group1', {
endpoints: [new ga_endpoints.NetworkLoadBalancerEndpoint(nlb1)],
});
listener.addEndpointGroup('Group2', {
// Imported load balancers automatically calculate their Region from the ARN.
// If you are load balancing to other resources, you must also pass a `region`
// parameter here.
endpoints: [new ga_endpoints.NetworkLoadBalancerEndpoint(nlb2)],
});
python
# Create an Accelerator
accelerator = globalaccelerator.Accelerator(self, "Accelerator")
# Create a Listener
listener = accelerator.add_listener("Listener",
port_ranges=[globalaccelerator.PortRange(from_port=80), globalaccelerator.PortRange(from_port=443)
]
)
# Import the Load Balancers
nlb1 = elbv2.NetworkLoadBalancer.from_network_load_balancer_attributes(self, "NLB1",
load_balancer_arn="arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b"
)
nlb2 = elbv2.NetworkLoadBalancer.from_network_load_balancer_attributes(self, "NLB2",
load_balancer_arn="arn:aws:elasticloadbalancing:ap-south-1:111111111111:loadbalancer/app/my-load-balancer2/5513dc2ea8a1"
)
# Add one EndpointGroup for each Region we are targeting
listener.add_endpoint_group("Group1",
endpoints=[ga_endpoints.NetworkLoadBalancerEndpoint(nlb1)]
)
listener.add_endpoint_group("Group2",
# Imported load balancers automatically calculate their Region from the ARN.
# If you are load balancing to other resources, you must also pass a `region`
# parameter here.
endpoints=[ga_endpoints.NetworkLoadBalancerEndpoint(nlb2)]
)
java
// Create an Accelerator
Accelerator accelerator = new Accelerator(this, "Accelerator");
// Create a Listener
Listener listener = accelerator.addListener("Listener", ListenerOptions.builder()
.portRanges(List.of(PortRange.builder().fromPort(80).build(), PortRange.builder().fromPort(443).build()))
.build());
// Import the Load Balancers
INetworkLoadBalancer nlb1 = NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(this, "NLB1", NetworkLoadBalancerAttributes.builder()
.loadBalancerArn("arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b")
.build());
INetworkLoadBalancer nlb2 = NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(this, "NLB2", NetworkLoadBalancerAttributes.builder()
.loadBalancerArn("arn:aws:elasticloadbalancing:ap-south-1:111111111111:loadbalancer/app/my-load-balancer2/5513dc2ea8a1")
.build());
// Add one EndpointGroup for each Region we are targeting
listener.addEndpointGroup("Group1", EndpointGroupOptions.builder()
.endpoints(List.of(new NetworkLoadBalancerEndpoint(nlb1)))
.build());
listener.addEndpointGroup("Group2", EndpointGroupOptions.builder()
// Imported load balancers automatically calculate their Region from the ARN.
// If you are load balancing to other resources, you must also pass a `region`
// parameter here.
.endpoints(List.of(new NetworkLoadBalancerEndpoint(nlb2)))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Create an Accelerator
var accelerator = new Accelerator(this, "Accelerator");
// Create a Listener
var listener = accelerator.AddListener("Listener", new ListenerOptions {
PortRanges = new [] { new PortRange { FromPort = 80 }, new PortRange { FromPort = 443 } }
});
// Import the Load Balancers
var nlb1 = NetworkLoadBalancer.FromNetworkLoadBalancerAttributes(this, "NLB1", new NetworkLoadBalancerAttributes {
LoadBalancerArn = "arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b"
});
var nlb2 = NetworkLoadBalancer.FromNetworkLoadBalancerAttributes(this, "NLB2", new NetworkLoadBalancerAttributes {
LoadBalancerArn = "arn:aws:elasticloadbalancing:ap-south-1:111111111111:loadbalancer/app/my-load-balancer2/5513dc2ea8a1"
});
// Add one EndpointGroup for each Region we are targeting
listener.AddEndpointGroup("Group1", new EndpointGroupOptions {
Endpoints = new [] { new NetworkLoadBalancerEndpoint(nlb1) }
});
listener.AddEndpointGroup("Group2", new EndpointGroupOptions {
// Imported load balancers automatically calculate their Region from the ARN.
// If you are load balancing to other resources, you must also pass a `region`
// parameter here.
Endpoints = new [] { new NetworkLoadBalancerEndpoint(nlb2) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Create an Accelerator
accelerator := globalaccelerator.NewAccelerator(this, jsii.String("Accelerator"))
// Create a Listener
listener := accelerator.AddListener(jsii.String("Listener"), &ListenerOptions{
PortRanges: []PortRange{
&PortRange{
FromPort: jsii.Number(80),
},
&PortRange{
FromPort: jsii.Number(443),
},
},
})
// Import the Load Balancers
nlb1 := elbv2.NetworkLoadBalancer_FromNetworkLoadBalancerAttributes(this, jsii.String("NLB1"), &NetworkLoadBalancerAttributes{
LoadBalancerArn: jsii.String("arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b"),
})
nlb2 := elbv2.NetworkLoadBalancer_FromNetworkLoadBalancerAttributes(this, jsii.String("NLB2"), &NetworkLoadBalancerAttributes{
LoadBalancerArn: jsii.String("arn:aws:elasticloadbalancing:ap-south-1:111111111111:loadbalancer/app/my-load-balancer2/5513dc2ea8a1"),
})
// Add one EndpointGroup for each Region we are targeting
listener.AddEndpointGroup(jsii.String("Group1"), &EndpointGroupOptions{
Endpoints: []IEndpoint{
ga_endpoints.NewNetworkLoadBalancerEndpoint(nlb1),
},
})
listener.AddEndpointGroup(jsii.String("Group2"), &EndpointGroupOptions{
// Imported load balancers automatically calculate their Region from the ARN.
// If you are load balancing to other resources, you must also pass a `region`
// parameter here.
Endpoints: []IEndpoint{
ga_endpoints.NewNetworkLoadBalancerEndpoint(nlb2),
},
})
Properties
loadBalancerArnstringload_balancer_arnstrloadBalancerArnStringLoadBalancerArnstringLoadBalancerArn*string required #ARN of the load balancer.
loadBalancerCanonicalHostedZoneIdoptionalstringload_balancer_canonical_hosted_zone_idoptionalstrloadBalancerCanonicalHostedZoneIdoptionalStringLoadBalancerCanonicalHostedZoneIdoptionalstringLoadBalancerCanonicalHostedZoneIdoptional*string #The canonical hosted zone ID of this load balancer.
Default: When not provided, LB cannot be used as Route53 Alias target.
loadBalancerDnsNameoptionalstringload_balancer_dns_nameoptionalstrloadBalancerDnsNameoptionalStringLoadBalancerDnsNameoptionalstringLoadBalancerDnsNameoptional*string #The DNS name of this load balancer.
Default: When not provided, LB cannot be used as Route53 Alias target.
loadBalancerSecurityGroupsoptionalstring[]load_balancer_security_groupsoptionaltyping.List[str]loadBalancerSecurityGroupsoptionalList<String>LoadBalancerSecurityGroupsoptionalstring[]LoadBalancerSecurityGroupsoptional*[]*string #Security groups to associate with this load balancer.
Default: No security groups associated with the load balancer.