java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.elasticloadbalancingv2.targets.AlbArnTarget
software.amazon.awscdk.services.elasticloadbalancingv2.targets.AlbTarget
All Implemented Interfaces:
INetworkLoadBalancerTarget, software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:49.672Z") @Stability(Stable) public class AlbTarget extends AlbArnTarget
A single Application Load Balancer as the target for load balancing.

Example:

 import software.amazon.awscdk.services.elasticloadbalancingv2.targets.*;
 import software.amazon.awscdk.services.ecs.*;
 import software.amazon.awscdk.services.ecs.patterns.*;
 Vpc vpc;
 FargateTaskDefinition task = FargateTaskDefinition.Builder.create(this, "Task").cpu(256).memoryLimitMiB(512).build();
 task.addContainer("nginx", ContainerDefinitionOptions.builder()
         .image(ContainerImage.fromRegistry("public.ecr.aws/nginx/nginx:latest"))
         .portMappings(List.of(PortMapping.builder().containerPort(80).build()))
         .build());
 ApplicationLoadBalancedFargateService svc = ApplicationLoadBalancedFargateService.Builder.create(this, "Service")
         .vpc(vpc)
         .taskDefinition(task)
         .publicLoadBalancer(false)
         .build();
 NetworkLoadBalancer nlb = NetworkLoadBalancer.Builder.create(this, "Nlb")
         .vpc(vpc)
         .crossZoneEnabled(true)
         .internetFacing(true)
         .build();
 NetworkListener listener = nlb.addListener("listener", BaseNetworkListenerProps.builder().port(80).build());
 listener.addTargets("Targets", AddNetworkTargetsProps.builder()
         .targets(List.of(new AlbTarget(svc.getLoadBalancer(), 80)))
         .port(80)
         .build());
 CfnOutput.Builder.create(this, "NlbEndpoint").value(String.format("http://%s", nlb.getLoadBalancerDnsName())).build();
 
  • Constructor Details

    • AlbTarget

      protected AlbTarget(software.amazon.jsii.JsiiObjectRef objRef)
    • AlbTarget

      protected AlbTarget(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • AlbTarget

      @Stability(Stable) public AlbTarget(@NotNull ApplicationLoadBalancer alb, @NotNull Number port)
      Parameters:
      alb - The application load balancer to load balance to. This parameter is required.
      port - The port on which the target is listening. This parameter is required.