Subchapter 96.2
references/adding-managed-rules-and-tuning-with-count-mode.mdMarkdown10 KBView on GitHub
Domain expertise for adding AWS Managed Rules rule groups to a web ACL and rolling them out without blocking legitimate traffic. Covers matching rule groups to the workload, the web ACL capacity unit (WCU) budget (the basic price covers up to 1,500 WCUs; a web ACL holds a hard maximum of 5,000), the Count-mode-first tuning path, and reading the triggering rule from logs to override just that rule rather than the whole group.
Does not cover rate-based rules, match rules, bot, or fraud rule groups; those are separate references. Logging must already be set up (see the logging reference).
Execute commands using the AWS MCP server when connected (sandboxed execution, audit logging, observability). Fall back to the AWS CLI otherwise.
To add managed rules and tune them end to end, follow the procedure exactly. See the Procedure section below.
The procedure covers:
| Workload | Rule group |
|---|---|
| Broad coverage (OWASP Top 10) | Core Rule Set (CRS) |
| Known exploit patterns | Known Bad Inputs |
| Database-backed application | SQL database rule group |
| Reputation filtering | Amazon IP reputation list, Anonymous IP list |
Constraints:
Each managed rule group consumes WCUs against the web ACL’s capacity. The basic web ACL price covers up to 1,500 WCUs; beyond that, usage is billed on a tiered model that AWS WAF adjusts automatically. The hard maximum for a web ACL is 5,000 WCUs. The Core Rule Set alone is 700, so a second large group moves into the priced tier quickly.
Constraints:
Adding a managed group straight in Block mode can take down legitimate traffic, because the predefined rules match patterns the application uses normally.
Constraints:
When a false positive appears, customers often disable the whole rule group and lose its protection. The fix is to override only the offending rule.
Constraints:
RuleActionOverrides, rather than disabling the groupOverrideAction to None when using individual RuleActionOverrides;
setting OverrideAction to Count overrides the whole group and the individual overrides have
no effectA managed rule is a false positive for this application. Find it in the logs and override just that rule to Count (Override one rule, not the whole group).
The combined rule groups exceed the 5,000 WCU hard maximum, which is not raisable. Trim or consolidate rules (WCU budget: 1,500 priced tier, 5,000 hard maximum). Note: crossing 1,500 WCUs does not cause this error; it only moves the web ACL into tiered pricing.
OverrideAction is set to Count for the whole group, which cancels individual overrides. Set
OverrideAction to None (Override one rule, not the whole group).
This procedure adds managed rule groups in Count mode within the WCU budget, tunes false positives, and switches to Block, then surfaces the console link.
Constraints for parameter acquisition:
Constraints:
aws sts get-caller-identityConstraints:
You MUST add each rule group with OverrideAction set to Count initially, tracking WCU usage
(the basic price covers up to 1,500 WCUs; the web ACL maximum is 5,000)
You MUST fetch the current LockToken with get-web-acl immediately before each update-web-acl
and pass the full rule set, since --rules is a complete replacement
You MUST preserve the web ACL’s existing DefaultAction from the get-web-acl response and pass
it back as {default_action}; do not assume Allow={}, since that would silently open all
unmatched traffic on a web ACL whose default action is Block:
aws wafv2 get-web-acl --name {web_acl_name} --scope {scope} --id {web_acl_id} --region {region}
aws wafv2 update-web-acl --name {web_acl_name} --scope {scope} --id {web_acl_id} \
--lock-token {lock_token} --default-action {default_action} \
--rules '[{"Name":"AWS-CRS","Priority":1,"Statement":{"ManagedRuleGroupStatement":{"VendorName":"AWS","Name":"AWSManagedRulesCommonRuleSet"}},"OverrideAction":{"Count":{}},"VisibilityConfig":{"SampledRequestsEnabled":true,"CloudWatchMetricsEnabled":true,"MetricName":"AWS-CRS"}}]' \
--visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName={web_acl_name} \
--region {region}Constraints:
RuleActionOverrides with
the group’s OverrideAction set to NoneConstraints:
You MUST switch the tuned groups to enforce by setting OverrideAction to None and let the
group’s own actions apply
You MUST present the web ACL console link and tell the customer to open it and confirm the rules and their actions:
https://us-east-1.console.aws.amazon.com/wafv2/homev2/web-acls?region={region}{
"web_acl_name": "example-webacl",
"web_acl_id": "abc",
"scope": "REGIONAL",
"rule_groups": ["AWSManagedRulesCommonRuleSet", "AWSManagedRulesKnownBadInputsRuleSet"]
}Added Core Rule Set (700 WCU) and Known Bad Inputs (200 WCU) in Count mode — 900 WCUs used (within the 1,500 base-price tier; web ACL max is 5,000).
Reviewed matches, overrode CrossSiteScripting_BODY to Count for the API path false positive.
Switched the rest to Block.
Open the web ACL and confirm the rules and actions:
https://us-east-1.console.aws.amazon.com/wafv2/homev2/web-acls?region=us-east-1Find the offending rule in the logs and override just it to Count (Step 3).
The groups exceed the 5,000 WCU maximum (not 1,500, which is only a pricing threshold). Trim or consolidate rules (Step 2).
This procedure modifies a security control, so misconfiguration directly weakens the application’s defenses.
wafv2: actions a task needs (for example wafv2:GetWebACL and wafv2:UpdateWebACL) rather than wafv2:* or the AWSWAFFullAccess managed policy.aws sts assume-role) rather than long-lived IAM user access keys when running these WAF CLI commands.wafv2 management events and set CloudWatch alarms on critical web ACL configuration changes (such as DeleteWebACL and UpdateWebACL rule removals) and on the web ACL’s BlockedRequests and CountedRequests metrics, so rule changes and sudden spikes in blocked or counted traffic are detected.