# AddApplicationActionProps

Properties for adding a new action to a listener.

Extends: [AddRuleProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.AddRuleProps.html)
Used as argument in: [IApplicationListener.addAction](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationListener.html#addaction)

- Source: [`aws-elasticloadbalancingv2/lib/alb/application-listener.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts#L982)
- Type last changed: v2.138.0 · 18 Apr 2024

## Example

TypeScript:

```ts
declare const listener: elbv2.ApplicationListener;

listener.addAction('Fixed', {
  priority: 10,
  conditions: [
    elbv2.ListenerCondition.pathPatterns(['/ok']),
  ],
  action: elbv2.ListenerAction.fixedResponse(200, {
    contentType: 'text/plain',
    messageBody: 'OK',
  })
});
```

Python:

```python
# listener: elbv2.ApplicationListener

listener.add_action("Fixed",
    priority=10,
    conditions=[
        elbv2.ListenerCondition.path_patterns(["/ok"])
    ],
    action=elbv2.ListenerAction.fixed_response(200,
        content_type="text/plain",
        message_body="OK"
    )
)
```

Java:

```java
ApplicationListener listener;

listener.addAction("Fixed", AddApplicationActionProps.builder()
        .priority(10)
        .conditions(List.of(ListenerCondition.pathPatterns(List.of("/ok"))))
        .action(ListenerAction.fixedResponse(200, FixedResponseOptions.builder()
                .contentType("text/plain")
                .messageBody("OK")
                .build()))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
ApplicationListener listener;

listener.AddAction("Fixed", new AddApplicationActionProps {
    Priority = 10,
    Conditions = new [] { ListenerCondition.PathPatterns(new [] { "/ok" }) },
    Action = ListenerAction.FixedResponse(200, new FixedResponseOptions {
        ContentType = "text/plain",
        MessageBody = "OK"
    })
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var listener ApplicationListener

listener.AddAction(jsii.String("Fixed"), &AddApplicationActionProps{
	Priority: jsii.Number(10),
	Conditions: []ListenerCondition{
		elbv2.ListenerCondition_PathPatterns([]*string{
			jsii.String("/ok"),
		}),
	},
	Action: elbv2.ListenerAction_FixedResponse(jsii.Number(200), &FixedResponseOptions{
		ContentType: jsii.String("text/plain"),
		MessageBody: jsii.String("OK"),
	}),
})
```

## Properties

- `action`: [ListenerAction](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ListenerAction.html) (required) — Action to perform.

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

  **Default:** No conditions.

- `priority`: number — Priority of this target group.

  **Default:** Target groups are used as defaults

  The rule with the lowest priority will be used for every request.
  If priority is not given, these target groups will be added as
  defaults, and must not have conditions.

  Priorities must be unique.

- `removeSuffix`: boolean — `ListenerRule`s have a `Rule` suffix on their logicalId by default. This allows you to remove that suffix.

  **Default:** use standard logicalId with the `Rule` suffix

  Legacy behavior of the `addTargetGroups()` convenience method did not include the `Rule` suffix on the logicalId of the generated `ListenerRule`.
  At some point, increasing complexity of requirements can require users to switch from the `addTargetGroups()` method
  to the `addAction()` method.
  When migrating `ListenerRule`s deployed by a legacy version of `addTargetGroups()`,
  you will need to enable this flag to avoid changing the logicalId of your resource.
  Otherwise Cfn will attempt to replace the `ListenerRule` and fail.
