class ListenerAction
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.ElasticLoadBalancingV2.ListenerAction |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awselasticloadbalancingv2#ListenerAction |
![]() | software.amazon.awscdk.services.elasticloadbalancingv2.ListenerAction |
![]() | aws_cdk.aws_elasticloadbalancingv2.ListenerAction |
![]() | aws-cdk-lib » aws_elasticloadbalancingv2 » ListenerAction |
Implements
IListener
What to do when a client makes a request to a listener.
Some actions can be combined with other ones (specifically, you can perform authentication before serving the request).
Multiple actions form a linked chain; the chain must always terminate in a (weighted)forward, fixedResponse or redirect action.
If an action supports chaining, the next action can be indicated
by passing it in the next
property.
(Called ListenerAction
instead of the more strictly correct
ListenerAction
because this is the class most users interact
with, and we want to make it not too visually overwhelming).
Example
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
declare const certificate: acm.Certificate;
declare const lb: elbv2.ApplicationLoadBalancer;
declare const bucket: s3.Bucket;
const trustStore = new elbv2.TrustStore(this, 'Store', {
bucket,
key: 'rootCA_cert.pem',
});
lb.addListener('Listener', {
port: 443,
protocol: elbv2.ApplicationProtocol.HTTPS,
certificates: [certificate],
// mTLS settings
mutualAuthentication: {
advertiseTrustStoreCaNames: true,
ignoreClientCertificateExpiry: false,
mutualAuthenticationMode: elbv2.MutualAuthenticationMode.VERIFY,
trustStore,
},
defaultAction: elbv2.ListenerAction.fixedResponse(200,
{ contentType: 'text/plain', messageBody: 'Success mTLS' }),
});
Initializer (protected)
super(defaultActionJson: ActionProperty, next?: ListenerAction)
Parameters
- defaultActionJson
Action
Property - next
Listener
Action
Create an instance of ListenerAction.
The default class should be good enough for most cases and should be created by using one of the static factory functions, but allow overriding to make sure we allow flexibility for the future.
Properties
Name | Type | Description |
---|---|---|
next? | Listener |
next?
Type:
Listener
(optional)
Methods
Name | Description |
---|---|
bind(scope, listener, associatingConstruct?) | Called when the action is being used in a listener. |
render | Render the listener default actions in this chain. |
render | Render the listener rule actions in this chain. |
protected add | Sets the Action for the ListenerRule . |
protected renumber(actions) | Renumber the "order" fields in the actions array. |
static authenticate | Authenticate using an identity provider (IdP) that is compliant with OpenID Connect (OIDC). |
static fixed | Return a fixed response. |
static forward(targetGroups, options?) | Forward to one or more Target Groups. |
static redirect(options) | Redirect to a different URI. |
static weighted | Forward to one or more Target Groups which are weighted differently. |
bind(scope, listener, associatingConstruct?)
public bind(scope: Construct, listener: IApplicationListener, associatingConstruct?: IConstruct): void
Parameters
- scope
Construct
- listener
IApplication
Listener - associatingConstruct
IConstruct
Called when the action is being used in a listener.
renderActions()
public renderActions(): ActionProperty[]
Returns
Render the listener default actions in this chain.
renderRuleActions()
public renderRuleActions(): ActionProperty[]
Returns
Render the listener rule actions in this chain.
protected addRuleAction(actionJson)
protected addRuleAction(actionJson: ActionProperty): void
Parameters
- actionJson
Action
— Action forProperty ListenerRule
.
Sets the Action for the ListenerRule
.
This method is required to set a dedicated Action to a ListenerRule
when the Action for the CfnListener
and the Action for the CfnListenerRule
have different structures. (e.g. AuthenticateOidcConfig
)
protected renumber(actions)
protected renumber(actions: ActionProperty[]): ActionProperty[]
Parameters
- actions
Action
Property []
Returns
Renumber the "order" fields in the actions array.
We don't number for 0 or 1 elements, but otherwise number them 1...#actions so ELB knows about the right order.
Do this in ListenerAction
instead of in Listener
so that we give
users the opportunity to override by subclassing and overriding renderActions
.
static authenticateOidc(options)
public static authenticateOidc(options: AuthenticateOidcOptions): ListenerAction
Parameters
- options
Authenticate
Oidc Options
Returns
Authenticate using an identity provider (IdP) that is compliant with OpenID Connect (OIDC).
static fixedResponse(statusCode, options?)
public static fixedResponse(statusCode: number, options?: FixedResponseOptions): ListenerAction
Parameters
- statusCode
number
- options
Fixed
Response Options
Returns
Return a fixed response.
static forward(targetGroups, options?)
public static forward(targetGroups: IApplicationTargetGroup[], options?: ForwardOptions): ListenerAction
Parameters
- targetGroups
IApplication
Target Group []
- options
Forward
Options
Returns
Forward to one or more Target Groups.
static redirect(options)
public static redirect(options: RedirectOptions): ListenerAction
Parameters
- options
Redirect
Options
Returns
Redirect to a different URI.
A URI consists of the following components: protocol://hostname:port/path?query. You must modify at least one of the following components to avoid a redirect loop: protocol, hostname, port, or path. Any components that you do not modify retain their original values.
You can reuse URI components using the following reserved keywords:
#{protocol}
#{host}
#{port}
#{path}
(the leading "/" is removed)#{query}
For example, you can change the path to "/new/#{path}", the hostname to "example.#{host}", or the query to "#{query}&value=xyz".
static weightedForward(targetGroups, options?)
public static weightedForward(targetGroups: WeightedTargetGroup[], options?: ForwardOptions): ListenerAction
Parameters
- targetGroups
Weighted
Target Group []
- options
Forward
Options
Returns
Forward to one or more Target Groups which are weighted differently.