aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationListener

class ApplicationListener (construct)

LanguageType name
.NETAmazon.CDK.AWS.ElasticLoadBalancingV2.ApplicationListener
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awselasticloadbalancingv2#ApplicationListener
Javasoftware.amazon.awscdk.services.elasticloadbalancingv2.ApplicationListener
Pythonaws_cdk.aws_elasticloadbalancingv2.ApplicationListener
TypeScript (source)aws-cdk-lib » aws_elasticloadbalancingv2 » ApplicationListener

Implements IConstruct, IDependable, IResource, IListener, IApplicationListener, IConnectable

Define an ApplicationListener.

Example

import { HttpAlbIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';

declare const lb: elbv2.ApplicationLoadBalancer;
const listener = lb.addListener('listener', { port: 80 });
listener.addTargets('target', {
  port: 80,
});

const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', {
  defaultIntegration: new HttpAlbIntegration('DefaultIntegration', listener, {
    parameterMapping: new apigwv2.ParameterMapping().custom('myKey', 'myValue'),
  }),
});

Initializer

new ApplicationListener(scope: Construct, id: string, props: ApplicationListenerProps)

Parameters

  • scope Construct
  • id string
  • props ApplicationListenerProps

Construct Props

NameTypeDescription
loadBalancerIApplicationLoadBalancerThe load balancer to attach this listener to.
certificates?IListenerCertificate[]Certificate list of ACM cert ARNs.
defaultAction?ListenerActionDefault action to take for requests to this listener.
defaultTargetGroups?IApplicationTargetGroup[]Default target groups to load balance to.
open?booleanAllow anyone to connect to the load balancer on the listener port.
port?numberThe port on which the listener listens for requests.
protocol?ApplicationProtocolThe protocol to use.
sslPolicy?SslPolicyThe security policy that defines which ciphers and protocols are supported.

loadBalancer

Type: IApplicationLoadBalancer

The load balancer to attach this listener to.


certificates?

Type: IListenerCertificate[] (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: ListenerAction (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: IApplicationTargetGroup[] (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.


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: ApplicationProtocol (optional, default: Determined from port if known.)

The protocol to use.


sslPolicy?

Type: SslPolicy (optional, default: The current predefined security policy.)

The security policy that defines which ciphers and protocols are supported.

Properties

NameTypeDescription
connectionsConnectionsManage connections to this ApplicationListener.
envResourceEnvironmentThe environment this resource belongs to.
listenerArnstringARN of the listener.
loadBalancerIApplicationLoadBalancerLoad balancer this listener is associated with.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.

connections

Type: Connections

Manage connections to this ApplicationListener.


env

Type: ResourceEnvironment

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: IApplicationLoadBalancer

Load balancer this listener is associated with.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.

Methods

NameDescription
addAction(id, props)Perform the given default action on incoming requests.
addCertificates(id, certificates)Add one or more certificates to this listener.
addTargetGroups(id, props)Load balance incoming requests to the given target groups.
addTargets(id, props)Load balance incoming requests to the given load balancing targets.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
registerConnectable(connectable, portRange)Register that a connectable that has been added to this load balancer.
toString()Returns a string representation of this construct.
protected validateListener()Validate this listener.
static fromApplicationListenerAttributes(scope, id, attrs)Import an existing listener.
static fromLookup(scope, id, options)Look up an ApplicationListener.

addAction(id, props)

public addAction(id: string, props: AddApplicationActionProps): void

Parameters

  • id string
  • props AddApplicationActionProps

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 IListenerCertificate[]

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 AddApplicationTargetGroupsProps

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 AddApplicationTargetsProps

Returns

  • ApplicationTargetGroup

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 RemovalPolicy

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.


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 ApplicationListenerAttributes

Returns

  • IApplicationListener

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 ApplicationListenerLookupOptions

Returns

  • IApplicationListener

Look up an ApplicationListener.