Hi, I wanted to create a cloudformation template in yaml for ip deny Rule but I end up with an error which I couldn't resolve. The code used and the error message is given below. Kindly help.

0
AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MyIPSet:
    Type: AWS::WAFv2::IPSet
    Properties:
      Name: MyIPSet
      Description: IP Set to deny access to specific IP addresses
      Scope: REGIONAL 
      IPAddressVersion: IPV4
      Addresses:
        - "192.0.2.44/32"

  MyIPSetRule:
    Type: AWS::WAFv2::RuleGroup
    Properties:
      Name: MyIPSetRule
      Description: Rule to use IPSet for denial
      Scope: REGIONAL 
      Capacity: 1
      "Rules": [
    {
        "Name": "IPSetDeny",
        "Priority": 0,
        "Statement": {
            "IPSetReferenceStatement": {
                "ARN": {
                    "Fn::GetAtt": [
                        "MyIPSet",
                        "Arn"
                    ]
                }
            }
        },
        "Action": {
            "Block": {}
        },
        "VisibilityConfig": {
            "SampledRequestsEnabled": true,
            "CloudWatchMetricsEnabled": true,
            "MetricName": "aws-waf-logs-dev-inf1"
        }
    }

 ]

ERROR MESSAGE: Resource handler returned message: "Model validation failed (#: required key [VisibilityConfig] not found)"

  • Hi, could you reformat you CFN code by making it a code block: use '</>' in the header of your question editor. It will make it more readable and allow us to help more efficiently

  • Sorry, code block used and updated the question.

  • An error pops after trying your answer "Resource handler returned message: "Error reason: The parameter contains formatting that is not valid., field: IP_ADDRESS, parameter: 192.0.2.44 (Service: Wafv2, Status Code: 400, Request ID: c36fab0f-e656-4505-b208-e9c443e5d0fb)" (RequestToken: 0656a642-5add-8fa5-cf93-0ccbab13ebe1, HandlerErrorCode: InvalidRequest)"

  • Will I still get an error if I use the CloudFormation template I created?

  • I guess so

Gowtham
asked 9 months ago335 views
1 Answer
1
Accepted Answer

Your template does not have "VisibilityConfig" in the rule group.
This is why the error is thought to be occurring.
So I think the following template will work.
The content has been changed from JSON to YAML, but it is the same.
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-rulegroup.html#cfn-wafv2-rulegroup-visibilityconfig

AWSTemplateFormatVersion: '2010-09-09' 
Resources: 
  MyIPSet: 
    Type: AWS::WAFv2::IPSet 
    Properties: 
      Name: MyIPSet 
      Description: IP Set to deny access to specific IP addresses 
      Scope: REGIONAL 
      IPAddressVersion: IPV4 
      Addresses: 
        - "192.0.2.44/32"

  MyIPSetRule: 
    Type: AWS::WAFv2::RuleGroup 
    Properties: 
      Name: MyIPSetRule 
      Description: Rule to use IPSet for denial 
      Scope: REGIONAL 
      Capacity: 1 
      Rules: 
        - Action: 
            Block: {}
          Name: IPSetDeny
          Priority: 0
          Statement: 
            IPSetReferenceStatement: 
              Arn: !GetAtt MyIPSet.Arn
          VisibilityConfig: 
            SampledRequestsEnabled: true
            CloudWatchMetricsEnabled: true
            MetricName: aws-waf-logs-dev-inf1
      VisibilityConfig:
        CloudWatchMetricsEnabled: true
        MetricName: waf-metric
        SampledRequestsEnabled: true
profile picture
EXPERT
answered 9 months ago
profile picture
EXPERT
reviewed 9 months ago
profile pictureAWS
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions

Relevant content