Custom response page in WAFv2 rule

Hi,
Is there any possibility of adding/creating custom response page in WAFv2 rule configuration?
I can’t find any example how this could be done. I’ve added reference to the existing manually created response page but this will likely to fail if that page doesn’t exist.

module waf {
  source                           = "../../modules/WAFv2"
  name_prefix                      = "test-waf"
  allow_default_action             = true
  create_alb_association           = false
  region                           = var.region
  aws-account-id                   = var.aws-account-id

  visibility_config = {
    cloudwatch_metrics_enabled     = false
    metric_name                    = "test-waf-waf-main-metrics"
    sampled_requests_enabled       = true
  }

  rules = [
    {
      name                         = "AWSManagedRulesCommonRuleSet-rule-1"
      priority                     = "1"
      action                       = "block"

      custom_response = {
        response_code = "403"
        custom_response_body_key = "403_test"
      }


      visibility_config = {
        cloudwatch_metrics_enabled = false
        metric_name                = "AWSManagedRulesCommonRuleSet-metric"
        sampled_requests_enabled   = true
      }

      managed_rule_group_statement = {
        name                       = "AWSManagedRulesCommonRuleSet"
        vendor_name                = "AWS"
        excluded_rule              = [
          "GenericRFI_QUERYARGUMENTS"
        ]
      }
    },
1 Like

@horizn same here. I don’t see anyway to do this right now.

Add this at end file config tf.

custom_response_body {
content = “WAF - Company”
content_type = “TEXT_PLAIN”
key = “custom_response”
}