Class ApplicationListener
- All Implemented Interfaces:
IResource
,IConnectable
,IApplicationListener
,IListener
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
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());
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IApplicationListener
IApplicationListener.Jsii$Default, IApplicationListener.Jsii$Proxy
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IListener
IListener.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ApplicationListener
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
ApplicationListener
(software.amazon.jsii.JsiiObjectRef objRef) ApplicationListener
(software.constructs.Construct scope, String id, ApplicationListenerProps props) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAction
(String id, AddApplicationActionProps props) Perform the given default action on incoming requests.void
addCertificates
(String id, List<IListenerCertificate> certificates) Add one or more certificates to this listener.void
addTargetGroups
(String id, AddApplicationTargetGroupsProps props) Load balance incoming requests to the given target groups.addTargets
(String id, AddApplicationTargetsProps props) Load balance incoming requests to the given load balancing targets.static IApplicationListener
fromApplicationListenerAttributes
(software.constructs.Construct scope, String id, ApplicationListenerAttributes attrs) Import an existing listener.static IApplicationListener
fromLookup
(software.constructs.Construct scope, String id, ApplicationListenerLookupOptions options) Look up an ApplicationListener.Manage connections to this ApplicationListener.Load balancer this listener is associated with.getPort()
The port of the listener.void
registerConnectable
(IConnectable connectable, Port portRange) Register that a connectable that has been added to this load balancer.Validate this listener.Methods inherited from class software.amazon.awscdk.services.elasticloadbalancingv2.BaseListener
getListenerArn, removeAttribute, setAttribute, setAttribute
Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResource
Methods inherited from class software.constructs.Construct
getNode, isConstruct, toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.constructs.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IListener
getListenerArn
Methods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
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 interfaceIApplicationListener
- 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 interfaceIApplicationListener
- 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 interfaceIApplicationListener
- 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 interfaceIApplicationListener
- 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 interfaceIApplicationListener
- Parameters:
connectable
- This parameter is required.portRange
- This parameter is required.
-
validateListener
Validate this listener.- Overrides:
validateListener
in classBaseListener
-
getConnections
Manage connections to this ApplicationListener.- Specified by:
getConnections
in interfaceIConnectable
-
getLoadBalancer
Load balancer this listener is associated with. -
getPort
The port of the listener.
-