class ApplicationListener (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.ElasticLoadBalancingV2.ApplicationListener |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awselasticloadbalancingv2#ApplicationListener |
![]() | software.amazon.awscdk.services.elasticloadbalancingv2.ApplicationListener |
![]() | aws_cdk.aws_elasticloadbalancingv2.ApplicationListener |
![]() | aws-cdk-lib » aws_elasticloadbalancingv2 » ApplicationListener |
Implements
IConstruct
, IDependable
, IResource
, IListener
, IApplication
, IConnectable
Define an ApplicationListener.
Example
import { AutoScalingGroup } from 'aws-cdk-lib/aws-autoscaling';
declare const asg: AutoScalingGroup;
declare const vpc: ec2.Vpc;
// Create the load balancer in a VPC. 'internetFacing' is 'false'
// by default, which creates an internal load balancer.
const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
vpc,
internetFacing: true
});
// Add a listener and open up the load balancer's security group
// to the world.
const listener = lb.addListener('Listener', {
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', {
port: 8080,
targets: [asg]
});
Initializer
new ApplicationListener(scope: Construct, id: string, props: ApplicationListenerProps)
Parameters
- scope
Construct
- id
string
- props
Application
Listener Props
Construct Props
Name | Type | Description |
---|---|---|
load | IApplication | The load balancer to attach this listener to. |
certificates? | IListener [] | Certificate list of ACM cert ARNs. |
default | Listener | Default action to take for requests to this listener. |
default | IApplication [] | Default target groups to load balance to. |
mutual | Mutual | The mutual authentication configuration information. |
open? | boolean | Allow anyone to connect to the load balancer on the listener port. |
port? | number | The port on which the listener listens for requests. |
protocol? | Application | The protocol to use. |
ssl | Ssl | The security policy that defines which ciphers and protocols are supported. |
loadBalancer
Type:
IApplication
The load balancer to attach this listener to.
certificates?
Type:
IListener
[]
(optional, default: No certificates.)
Certificate list of ACM cert ARNs.
You must provide exactly one certificate if the listener protocol is HTTPS or TLS.
defaultAction?
Type:
Listener
(optional, default: None.)
Default action to take for requests to this listener.
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.
Cannot be specified together with defaultTargetGroups
.
defaultTargetGroups?
Type:
IApplication
[]
(optional, default: None.)
Default target groups to load balance to.
All target groups will be load balanced to with equal weight and without
stickiness. For a more complex configuration than that, use
either defaultAction
or addAction()
.
Cannot be specified together with defaultAction
.
mutualAuthentication?
Type:
Mutual
(optional, default: No mutual authentication configuration)
The mutual authentication configuration information.
open?
Type:
boolean
(optional, default: true)
Allow anyone to connect to the load balancer on the listener port.
If this is specified, the load balancer will be opened up to anyone who can reach it. For internal load balancers this is anyone in the same VPC. For public load balancers, this is anyone on the internet.
If you want to be more selective about who can access this load
balancer, set this to false
and use the listener's connections
object to selectively grant access to the load balancer on the listener port.
port?
Type:
number
(optional, default: Determined from protocol if known.)
The port on which the listener listens for requests.
protocol?
Type:
Application
(optional, default: Determined from port if known.)
The protocol to use.
sslPolicy?
Type:
Ssl
(optional, default: The current predefined security policy.)
The security policy that defines which ciphers and protocols are supported.
Properties
Name | Type | Description |
---|---|---|
connections | Connections | Manage connections to this ApplicationListener. |
env | Resource | The environment this resource belongs to. |
listener | string | ARN of the listener. |
load | IApplication | Load balancer this listener is associated with. |
node | Node | The tree node. |
port | number | The port of the listener. |
stack | Stack | The stack in which this resource is defined. |
connections
Type:
Connections
Manage connections to this ApplicationListener.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
listenerArn
Type:
string
ARN of the listener.
loadBalancer
Type:
IApplication
Load balancer this listener is associated with.
node
Type:
Node
The tree node.
port
Type:
number
The port of the listener.
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
add | Perform the given default action on incoming requests. |
add | Add one or more certificates to this listener. |
add | Load balance incoming requests to the given target groups. |
add | Load balance incoming requests to the given load balancing targets. |
apply | Apply the given removal policy to this resource. |
register | Register that a connectable that has been added to this load balancer. |
remove | Remove an attribute from the listener. |
set | Set a non-standard attribute on the listener. |
to | Returns a string representation of this construct. |
protected validate | Validate this listener. |
static from | Import an existing listener. |
static from | Look up an ApplicationListener. |
addAction(id, props)
public addAction(id: string, props: AddApplicationActionProps): void
Parameters
- id
string
- props
Add
Application Action 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).
addCertificates(id, certificates)
public addCertificates(id: string, certificates: IListenerCertificate[]): void
Parameters
- id
string
- certificates
IListener
Certificate []
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.
addTargetGroups(id, props)
public addTargetGroups(id: string, props: AddApplicationTargetGroupsProps): void
Parameters
- id
string
- props
Add
Application Target Groups 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).
addTargets(id, props)
public addTargets(id: string, props: AddApplicationTargetsProps): ApplicationTargetGroup
Parameters
- id
string
- props
Add
Application Targets Props
Returns
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.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
registerConnectable(connectable, portRange)
public registerConnectable(connectable: IConnectable, portRange: Port): void
Parameters
- connectable
IConnectable
- portRange
Port
Register that a connectable that has been added to this load balancer.
Don't call this directly. It is called by ApplicationTargetGroup.
removeAttribute(key)
public removeAttribute(key: string): void
Parameters
- key
string
Remove an attribute from the listener.
setAttribute(key, value?)
public setAttribute(key: string, value?: string): void
Parameters
- key
string
- value
string
Set a non-standard attribute on the listener.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
protected validateListener()
protected validateListener(): string[]
Returns
string[]
Validate this listener.
static fromApplicationListenerAttributes(scope, id, attrs)
public static fromApplicationListenerAttributes(scope: Construct, id: string, attrs: ApplicationListenerAttributes): IApplicationListener
Parameters
- scope
Construct
- id
string
- attrs
Application
Listener Attributes
Returns
Import an existing listener.
static fromLookup(scope, id, options)
public static fromLookup(scope: Construct, id: string, options: ApplicationListenerLookupOptions): IApplicationListener
Parameters
- scope
Construct
- id
string
- options
Application
Listener Lookup Options
Returns
Look up an ApplicationListener.