Search code examples
amazon-web-servicesaws-cloudformation

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


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


Solution

  • AWS::StackName missed the AWS:: prefix


    CloudFormation Linter in VSCode shows 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