Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

AWS::ElasticLoadBalancingV2::ListenerRule

The AWS::ElasticLoadBalancingV2::ListenerRule resource defines which requests an Elastic Load Balancing listener takes action on and the action that it takes. For more information, see the Listeners for Your Application Load Balancers in the Application Load Balancers Guide.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

Copy
{ "Type" : "AWS::ElasticLoadBalancingV2::ListenerRule", "Properties" : { "Actions" : [ Actions, ... ], "Conditions" : [ Conditions, ... ], "ListenerArn" : String, "Priority" : Integer } }

YAML

Copy
Type: "AWS::ElasticLoadBalancingV2::ListenerRule" Properties: Actions: - Actions Conditions: - Conditions ListenerArn: String Priority: Integer

Properties

Actions

The action that the listener takes when a request meets the specified condition.

Required: Yes

Type: List of Elastic Load Balancing ListenerRule Actions

Update requires: No interruption

Conditions

The conditions under which a rule takes effect.

Required: Yes

Type: List of Elastic Load Balancing ListenerRule Conditions

Update requires: No interruption

ListenerArn

The Amazon Resource Name (ARN) of the listener that the rule applies to.

Required: Yes

Type: String

Update requires: Replacement

Priority

The priority for the rule. Elastic Load Balancing evaluates rules in priority order, from the lowest value to the highest value. If a request satisfies a rule, Elastic Load Balancing ignores all subsequent rules.

Note

A target group can have only one rule with a given priority.

For valid values, see the Priority parameter for the CreateRule action in the Elastic Load Balancing API Reference version 2015-12-01.

Required: Yes

Type: Integer

Update requires: No interruption

Return Value

Ref

When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the rule's ARN, such as arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/9683b2d02a6cabee.

For more information about using the Ref function, see Ref.

Example

The following example creates a rule that forwards requests to the TargetGroup target group if the request URL contains the /img/* pattern.

JSON

Copy
"ListenerRule": { "Type": "AWS::ElasticLoadBalancingV2::ListenerRule", "Properties": { "Actions": [{ "Type": "forward", "TargetGroupArn": { "Ref": "TargetGroup" } }], "Conditions": [{ "Field": "path-pattern", "Values": [ "/img/*" ] }], "ListenerArn": { "Ref": "Listener" }, "Priority": 1 } }

YAML

Copy
ListenerRule: Type: AWS::ElasticLoadBalancingV2::ListenerRule Properties: Actions: - Type: forward TargetGroupArn: Ref: TargetGroup Conditions: - Field: path-pattern Values: - "/img/*" ListenerArn: Ref: Listener Priority: 1