aws-cdk-lib.aws_elasticloadbalancingv2.ListenerAction

class ListenerAction

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

Implements IListenerAction

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

declare const listener: elbv2.ApplicationListener;
declare const myTargetGroup: elbv2.ApplicationTargetGroup;

listener.addAction('DefaultAction', {
  action: elbv2.ListenerAction.authenticateOidc({
    authorizationEndpoint: 'https://example.com/openid',
    // Other OIDC properties here
    clientId: '...',
    clientSecret: SecretValue.secretsManager('...'),
    issuer: '...',
    tokenEndpoint: '...',
    userInfoEndpoint: '...',

    // Next
    next: elbv2.ListenerAction.forward([myTargetGroup]),
  }),
});

Initializer (protected)

super(defaultActionJson: ActionProperty, next?: ListenerAction)

Parameters

  • defaultActionJson ActionProperty
  • next ListenerAction

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

NameTypeDescription
next?ListenerAction

next?

Type: ListenerAction (optional)

Methods

NameDescription
bind(scope, listener, associatingConstruct?)Called when the action is being used in a listener.
renderActions()Render the listener default actions in this chain.
renderRuleActions()Render the listener rule actions in this chain.
protected addRuleAction(actionJson)Sets the Action for the ListenerRule.
protected renumber(actions)Renumber the "order" fields in the actions array.
static authenticateOidc(options)Authenticate using an identity provider (IdP) that is compliant with OpenID Connect (OIDC).
static fixedResponse(statusCode, options?)Return a fixed response.
static forward(targetGroups, options?)Forward to one or more Target Groups.
static redirect(options)Redirect to a different URI.
static weightedForward(targetGroups, options?)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 IApplicationListener
  • associatingConstruct IConstruct

Called when the action is being used in a listener.


renderActions()

public renderActions(): ActionProperty[]

Returns

  • ActionProperty[]

Render the listener default actions in this chain.


renderRuleActions()

public renderRuleActions(): ActionProperty[]

Returns

  • ActionProperty[]

Render the listener rule actions in this chain.


protected addRuleAction(actionJson)

protected addRuleAction(actionJson: ActionProperty): void

Parameters

  • actionJson ActionProperty — Action for 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 ActionProperty[]

Returns

  • ActionProperty[]

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 AuthenticateOidcOptions

Returns

  • ListenerAction

Authenticate using an identity provider (IdP) that is compliant with OpenID Connect (OIDC).

See also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-authenticate-users.html#oidc-requirements


static fixedResponse(statusCode, options?)

public static fixedResponse(statusCode: number, options?: FixedResponseOptions): ListenerAction

Parameters

  • statusCode number
  • options FixedResponseOptions

Returns

  • ListenerAction

Return a fixed response.

See also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#fixed-response-actions


static forward(targetGroups, options?)

public static forward(targetGroups: IApplicationTargetGroup[], options?: ForwardOptions): ListenerAction

Parameters

  • targetGroups IApplicationTargetGroup[]
  • options ForwardOptions

Returns

  • ListenerAction

Forward to one or more Target Groups.

See also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#forward-actions


static redirect(options)

public static redirect(options: RedirectOptions): ListenerAction

Parameters

  • options RedirectOptions

Returns

  • ListenerAction

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".

See also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#redirect-actions


static weightedForward(targetGroups, options?)

public static weightedForward(targetGroups: WeightedTargetGroup[], options?: ForwardOptions): ListenerAction

Parameters

  • targetGroups WeightedTargetGroup[]
  • options ForwardOptions

Returns

  • ListenerAction

Forward to one or more Target Groups which are weighted differently.

See also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#forward-actions