Class ApplicationListener

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.elasticloadbalancingv2.BaseListener
software.amazon.awscdk.services.elasticloadbalancingv2.ApplicationListener
All Implemented Interfaces:
IResource, IConnectable, IApplicationListener, IListener, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-24T21:00:29.782Z") @Stability(Stable) public class ApplicationListener extends BaseListener implements IApplicationListener
Define an ApplicationListener.

Example:

 import software.amazon.awscdk.services.autoscaling.AutoScalingGroup;
 AutoScalingGroup asg;
 Vpc vpc;
 // Create the load balancer in a VPC. 'internetFacing' is 'false'
 // by default, which creates an internal load balancer.
 ApplicationLoadBalancer lb = ApplicationLoadBalancer.Builder.create(this, "LB")
         .vpc(vpc)
         .internetFacing(true)
         .build();
 // Add a listener and open up the load balancer's security group
 // to the world.
 ApplicationListener listener = lb.addListener("Listener", BaseApplicationListenerProps.builder()
         .port(80)
         // 'open: true' is the default, you can leave it out if you want. Set it
         // to 'false' and use `listener.connections` if you want to be selective
         // about who can access the load balancer.
         .open(true)
         .build());
 // Create an AutoScaling group and add it as a load balancing
 // target to the listener.
 listener.addTargets("ApplicationFleet", AddApplicationTargetsProps.builder()
         .port(8080)
         .targets(List.of(asg))
         .build());
 
  • Constructor Details

    • ApplicationListener

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

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

      @Stability(Stable) public ApplicationListener(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull ApplicationListenerProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • fromApplicationListenerAttributes

      @Stability(Stable) @NotNull public static IApplicationListener fromApplicationListenerAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull ApplicationListenerAttributes attrs)
      Import an existing listener.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      attrs - This parameter is required.
    • fromLookup

      @Stability(Stable) @NotNull public static IApplicationListener fromLookup(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull ApplicationListenerLookupOptions options)
      Look up an ApplicationListener.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      options - This parameter is required.
    • addAction

      @Stability(Stable) public void addAction(@NotNull String id, @NotNull AddApplicationActionProps props)
      Perform the given default action on incoming requests.

      This allows full control of the default action of the load balancer, including Action chaining, fixed responses and redirect responses. See the ListenerAction class for all options.

      It's possible to add routing conditions to the Action added in this way. At least one Action must be added without conditions (which becomes the default Action).

      Specified by:
      addAction in interface IApplicationListener
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • addCertificates

      @Stability(Stable) public void addCertificates(@NotNull String id, @NotNull List<IListenerCertificate> certificates)
      Add one or more certificates to this listener.

      After the first certificate, this creates ApplicationListenerCertificates resources since cloudformation requires the certificates array on the listener resource to have a length of 1.

      Specified by:
      addCertificates in interface IApplicationListener
      Parameters:
      id - This parameter is required.
      certificates - This parameter is required.
    • addTargetGroups

      @Stability(Stable) public void addTargetGroups(@NotNull String id, @NotNull AddApplicationTargetGroupsProps props)
      Load balance incoming requests to the given target groups.

      All target groups will be load balanced to with equal weight and without stickiness. For a more complex configuration than that, use addAction().

      It's possible to add routing conditions to the TargetGroups added in this way. At least one TargetGroup must be added without conditions (which will become the default Action for this listener).

      Specified by:
      addTargetGroups in interface IApplicationListener
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • addTargets

      @Stability(Stable) @NotNull public ApplicationTargetGroup addTargets(@NotNull String id, @NotNull AddApplicationTargetsProps props)
      Load balance incoming requests to the given load balancing targets.

      This method implicitly creates an ApplicationTargetGroup for the targets involved, and a 'forward' action to route traffic to the given TargetGroup.

      If you want more control over the precise setup, create the TargetGroup and use addAction yourself.

      It's possible to add conditions to the targets added in this way. At least one set of targets must be added without conditions.

      Specified by:
      addTargets in interface IApplicationListener
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
      Returns:
      The newly created target group
    • registerConnectable

      @Stability(Stable) public void registerConnectable(@NotNull IConnectable connectable, @NotNull Port portRange)
      Register that a connectable that has been added to this load balancer.

      Don't call this directly. It is called by ApplicationTargetGroup.

      Specified by:
      registerConnectable in interface IApplicationListener
      Parameters:
      connectable - This parameter is required.
      portRange - This parameter is required.
    • validateListener

      @Stability(Stable) @NotNull protected List<String> validateListener()
      Validate this listener.
      Overrides:
      validateListener in class BaseListener
    • getConnections

      @Stability(Stable) @NotNull public Connections getConnections()
      Manage connections to this ApplicationListener.
      Specified by:
      getConnections in interface IConnectable
    • getLoadBalancer

      @Stability(Stable) @NotNull public IApplicationLoadBalancer getLoadBalancer()
      Load balancer this listener is associated with.