Invalid request provided: AWS::ElasticLoadBalancingV2::ListenerRule Validation exception

Viewed 4480

I need to create just a TargetGroup and ListenerRule with the CloudFormation but i received error.

My CloudFormation:

TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Name: !Sub ${StackName}-alb
      VpcId: !Ref VpcId
      Port: !Ref ContainerPort
      Protocol: HTTP
      Matcher:
        HttpCode: 200
      HealthCheckIntervalSeconds: 10
      HealthCheckPath: !Ref HealthCheckPath
      HealthCheckProtocol: HTTP
      HealthCheckTimeoutSeconds: 5
      HealthyThresholdCount: 2
      TargetType: ip
      TargetGroupAttributes:
        - Key: deregistration_delay.timeout_seconds
          Value: 30

  ListenerRule:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    DependsOn: 
      - TargetGroup
    Properties:
      Actions:
        - Type: forward
          TargetGroupArn: !Ref TargetGroup
      Conditions:
        - Field: host-header
          Values:
            - "www.mydominian.*"
      ListenerArn: !Ref ListenerArn
      Priority: 164

Invalid request provided So, the error is the image

5 Answers

It's just missing the HostHeaderConfig in the Conditions section. Update it to the following:

Conditions:
  - Field: host-header
    HostHeaderConfig:
      Values:
        - "www.mydominian.*"

When you define Field, you'll need to use the correct Config section. Unfortunately, it's not smart enough to know which one to apply your pattern to.

For example, if you were using path-based routing it would look like this:

Conditions: 
  - Field: path-pattern
    PathPatternConfig:
      Values:
        - "/api/micro-service-1/*"

CloudFormation will also throw this "Invalid request provided" error if the permissions of the deploying user are incorrect.

We had to add an elasticloadbalancing:CreateRule Action, and supply the correct ARN conditions for the listener as well as a listener-rule wildcard in the Resource collection of the policy.

{
    "Effect": "Allow",
    "Action": [
        "elasticloadbalancing:CreateRule"
    ],
    "Resource": [
        "arn:aws:elasticloadbalancing:<region>:<account-id>:listener/app/<lb name>/<lb-id>/<listener-id>",
        "arn:aws:elasticloadbalancing:<region>:<account-id>:listener-rule/app/<lb name>/<lb-id>/<listener-id>/*"
    ]
}

Hope this helps someone else.

AWS::StackName looks like it's missing the AWS:: prefix


Recommend trying the CloudFormation Linter in VSCode to see some of these errors inline while authoring templates along with autocompletion and documentation links:

Visual Studio Code extension

[cfn-lint] E1019: Parameter StackName for Fn::Sub not found at Resources/TargetGroup/Properties/Name/Fn::Sub

I would like to share that in my case the course of the problem was the number of conditions in the rule. I had them 6 instead of 5.

Quotas for your Application Load Balancers, where

Rule

  • Match evaluations per rule: 5

Ensure "Condition Values per Rule" doesn't exceed the quota of 5 rules per listener. The web console can help with that:

EC2
  -> Load Balancers
    -> [Select your load balancer]
      -> Listeners
        -> View/Edit Rules 
          -> Rule limits for condition values, wildcards, and total rules
Related