# ApplicationListenerRule

Define a new listener rule.

Extends: Construct › ApplicationListenerRule
Implements: IConstruct, IDependable

- Source: [`aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts`](https://github.com/aws/aws-cdk/blob/v2.276.0/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts#L205)

## Example

```ts
declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.TaskDefinition;
declare const blueTargetGroup: elbv2.ApplicationTargetGroup;
declare const greenTargetGroup: elbv2.ApplicationTargetGroup;
declare const prodListenerRule: elbv2.ApplicationListenerRule;

const service = new ecs.FargateService(this, 'Service', {
  cluster,
  taskDefinition,
  deploymentStrategy: ecs.DeploymentStrategy.LINEAR,
  linearConfiguration: {
    stepPercent: 10.0,
    stepBakeTime: Duration.minutes(5),
  },
});

const target = service.loadBalancerTarget({
  containerName: 'web',
  containerPort: 80,
  alternateTarget: new ecs.AlternateTarget('AlternateTarget', {
    alternateTargetGroup: greenTargetGroup,
    productionListener: ecs.ListenerRuleConfiguration.applicationListenerRule(prodListenerRule),
  }),
});

target.attachToApplicationTargetGroup(blueTargetGroup);
```

## Initializer

```ts
new ApplicationListenerRule(scope: Construct, id: string, props: ApplicationListenerRuleProps)
```

## Construct Props

- `action`: [ListenerAction](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ListenerAction.html) — Action to perform when requests are received.

  **Default:** No action

  Only one of `action`, `fixedResponse`, `redirectResponse` or `targetGroups` can be specified.

- `conditions`: [ListenerCondition](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ListenerCondition.html)[] — Rule applies if matches the conditions.

  **Default:** No conditions.

- `listener`: [IApplicationListener](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationListener.html) (required) — The listener to attach the rule to.

- `priority`: number (required) — Priority of the rule.

  The rule with the lowest priority will be used for every request.

  Priorities must be unique.

- `targetGroups`: [IApplicationTargetGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationTargetGroup.html)[] — Target groups to forward requests to.

  **Default:** No target groups.

  Only one of `action`, `fixedResponse`, `redirectResponse` or `targetGroups` can be specified.

  Implies a `forward` action.

## Properties

- `listenerRuleArn`: string — The ARN of this rule.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

## Methods

- `addCondition(condition: ListenerCondition): void` — Add a non-standard condition to this rule.

- `configureAction(action: ListenerAction): void` — Configure the action to perform for this rule.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
