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.InitializationModeNested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IApplicationListener
IApplicationListener.Jsii$Default, IApplicationListener.Jsii$ProxyNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IListener
IListener.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedApplicationListener(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedApplicationListener(software.amazon.jsii.JsiiObjectRef objRef) ApplicationListener(software.constructs.Construct scope, String id, ApplicationListenerProps props) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAction(String id, AddApplicationActionProps props) Perform the given default action on incoming requests.voidaddCertificates(String id, List<IListenerCertificate> certificates) Add one or more certificates to this listener.voidaddTargetGroups(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 IApplicationListenerfromApplicationListenerAttributes(software.constructs.Construct scope, String id, ApplicationListenerAttributes attrs) Import an existing listener.static IApplicationListenerfromLookup(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.voidregisterConnectable(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, setAttributeMethods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.constructs.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IListener
getListenerArnMethods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStackMethods 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
ListenerActionclass 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:
addActionin 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:
addCertificatesin 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:
addTargetGroupsin 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
addActionyourself.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:
addTargetsin 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:
registerConnectablein interfaceIApplicationListener- Parameters:
connectable- This parameter is required.portRange- This parameter is required.
-
validateListener
Validate this listener.- Overrides:
validateListenerin classBaseListener
-
getConnections
Manage connections to this ApplicationListener.- Specified by:
getConnectionsin interfaceIConnectable
-
getLoadBalancer
Load balancer this listener is associated with. -
getPort
The port of the listener.
-