Class ApplicationListener
Define an ApplicationListener.
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.ElasticLoadBalancingV2
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class ApplicationListener : BaseListener, IApplicationListener, IListener, IResource, IConnectable
Syntax (vb)
Public Class ApplicationListener
Inherits BaseListener
Implements IApplicationListener, IListener, IResource, IConnectable
Remarks
Resource: AWS::ElasticLoadBalancingV2::Listener
ExampleMetadata: infused
Examples
using Amazon.CDK.AWS.AutoScaling;
AutoScalingGroup asg;
Vpc vpc;
// Create the load balancer in a VPC. 'internetFacing' is 'false'
// by default, which creates an internal load balancer.
var lb = new ApplicationLoadBalancer(this, "LB", new ApplicationLoadBalancerProps {
Vpc = vpc,
InternetFacing = true
});
// Add a listener and open up the load balancer's security group
// to the world.
var listener = lb.AddListener("Listener", new BaseApplicationListenerProps {
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
});
// Create an AutoScaling group and add it as a load balancing
// target to the listener.
listener.AddTargets("ApplicationFleet", new AddApplicationTargetsProps {
Port = 8080,
Targets = new [] { asg }
});
Synopsis
Constructors
ApplicationListener(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
ApplicationListener(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
ApplicationListener(Construct, String, IApplicationListenerProps) |
Properties
Connections | Manage connections to this ApplicationListener. |
LoadBalancer | Load balancer this listener is associated with. |
Methods
AddAction(String, IAddApplicationActionProps) | Perform the given default action on incoming requests. |
AddCertificates(String, IListenerCertificate[]) | Add one or more certificates to this listener. |
AddTargetGroups(String, IAddApplicationTargetGroupsProps) | Load balance incoming requests to the given target groups. |
AddTargets(String, IAddApplicationTargetsProps) | Load balance incoming requests to the given load balancing targets. |
FromApplicationListenerAttributes(Construct, String, IApplicationListenerAttributes) | Import an existing listener. |
FromLookup(Construct, String, IApplicationListenerLookupOptions) | Look up an ApplicationListener. |
RegisterConnectable(IConnectable, Port) | Register that a connectable that has been added to this load balancer. |
ValidateListener() | Validate this listener. |
Constructors
ApplicationListener(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected ApplicationListener(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
ApplicationListener(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected ApplicationListener(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
ApplicationListener(Construct, String, IApplicationListenerProps)
public ApplicationListener(Construct scope, string id, IApplicationListenerProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props IApplicationListenerProps
Properties
Connections
Manage connections to this ApplicationListener.
public virtual Connections_ Connections { get; }
Property Value
LoadBalancer
Load balancer this listener is associated with.
public virtual IApplicationLoadBalancer LoadBalancer { get; }
Property Value
Methods
AddAction(String, IAddApplicationActionProps)
Perform the given default action on incoming requests.
public virtual void AddAction(string id, IAddApplicationActionProps props)
Parameters
- id System.String
- props IAddApplicationActionProps
Remarks
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).
AddCertificates(String, IListenerCertificate[])
Add one or more certificates to this listener.
public virtual void AddCertificates(string id, IListenerCertificate[] certificates)
Parameters
- id System.String
- certificates IListenerCertificate[]
Remarks
After the first certificate, this creates ApplicationListenerCertificates resources since cloudformation requires the certificates array on the listener resource to have a length of 1.
AddTargetGroups(String, IAddApplicationTargetGroupsProps)
Load balance incoming requests to the given target groups.
public virtual void AddTargetGroups(string id, IAddApplicationTargetGroupsProps props)
Parameters
- id System.String
- props IAddApplicationTargetGroupsProps
Remarks
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).
AddTargets(String, IAddApplicationTargetsProps)
Load balance incoming requests to the given load balancing targets.
public virtual ApplicationTargetGroup AddTargets(string id, IAddApplicationTargetsProps props)
Parameters
- id System.String
- props IAddApplicationTargetsProps
Returns
The newly created target group
Remarks
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.
FromApplicationListenerAttributes(Construct, String, IApplicationListenerAttributes)
Import an existing listener.
public static IApplicationListener FromApplicationListenerAttributes(Construct scope, string id, IApplicationListenerAttributes attrs)
Parameters
- scope Constructs.Construct
- id System.String
- attrs IApplicationListenerAttributes
Returns
FromLookup(Construct, String, IApplicationListenerLookupOptions)
Look up an ApplicationListener.
public static IApplicationListener FromLookup(Construct scope, string id, IApplicationListenerLookupOptions options)
Parameters
- scope Constructs.Construct
- id System.String
- options IApplicationListenerLookupOptions
Returns
RegisterConnectable(IConnectable, Port)
Register that a connectable that has been added to this load balancer.
public virtual void RegisterConnectable(IConnectable connectable, Port portRange)
Parameters
- connectable IConnectable
- portRange Port
Remarks
Don't call this directly. It is called by ApplicationTargetGroup.
ValidateListener()
Validate this listener.
protected override string[] ValidateListener()
Returns
System.String[]