Turn On AWS WAF Without Blocking Real Users: Count Mode, Logs, Tuning, Then Block

Turn On AWS WAF Without Blocking Real Users: Count Mode, Logs, Tuning, Then Block

I ran AWS WAF managed rules in Count mode against real-looking traffic, found three false positives in the logs, fixed them with label-based exceptions instead of disabling rules, then switched to Block. Queries, rule JSON, results and logging costs.

DevSecOps Engineer & AWS Community Builder | Cloud Security
There are two easy ways to get AWS WAF managed rules wrong. Switch them on in Block mode, and a file upload or a CMS save can start failing the same afternoon. Or worry about exactly that and leave them in Count mode for months, logging attacks and stopping nothing.
There's a middle path, and AWS documents it: run everything in Count, read what would have been blocked, add narrow exceptions for your real traffic, then switch to Block one rule at a time. This article walks through that process on a test application, with the logs, the exact rules and the results at each stage.
I tested this on 23 November 2026. Short version:
  • In Count mode, three normal requests matched rules that would have blocked them: a 12 KB JSON upload, a health check with no  User-Agent  header, and a CMS save containing a  <script>  tag.
  • Switching every other rule to Block stopped all four attack requests and broke nothing. But the three noisy rules, left on Count, also let the same patterns through on every other path.
  • Three small label-based rules closed that gap. Final result: 4 out of 4 legitimate requests allowed, 7 out of 7 attack and probe requests blocked.
Everything you need to reproduce it, including a CloudFormation template, the Lambda code and the queries, is on GitHub:  aws-waf-count-to-block-lab .
Audience: cloud and DevOps engineers running public applications behind an Application Load Balancer, API Gateway or CloudFront. Level: intermediate.

How managed rules, Count and labels fit together

Three features make this process work.
Rule action overrides. You can override every rule inside a managed rule group to Count. AWS describes this as the most common use of overrides: testing and monitoring a rule group before putting it into production ( AWS WAF docs ). A counted request isn't blocked, and WAF keeps evaluating the rest of the web ACL.
Labels. When a managed rule matches, it adds a label to the request, such as  awswaf:managed:aws:core-rule-set:CrossSiteScripting_Body . The rule still adds its label when you've overridden it to Count. AWS documents this as the intended pattern: override the rule group's rules to Count, then run a rule after the group that acts on the labels ( AWS WAF docs ).
Label match rules. A rule placed later in the web ACL can check for that label and make its own decision. That's how you build an exception: leave the noisy managed rule on Count, and add your own rule that blocks when the label is present and the request isn't the legitimate case. The AWS Security Blog describes exactly this pattern for handling false positives ( AWS Security Blog ).
The alternative, a scope-down statement on the rule group, removes matching requests from inspection by every rule in the group, not just the noisy one ( re:Post ). Labels let you make an exception for one rule while everything else keeps inspecting the request.

The lab

Everything ran in  us-east-1  in my own AWS account.
Component
Setup
Application
A Lambda function behind an Application Load Balancer that returns  200 ok  for any request
Web ACL
 AWSManagedRulesCommonRuleSet  (the Core rule set, default version  Version_1.23 ) and  AWSManagedRulesKnownBadInputsRuleSet , default action Allow
Logging
CloudWatch Logs log group  aws-waf-logs-waf-lab , 1 week retention
Traffic
A second Lambda function that sends 8 requests and tags each with an  X-Lab-Case  header so I can find it in the logs
Lab architecture: traffic Lambda and internal ALB in private subnets, AWS WAF web ACL on the ALB, echo Lambda target, WAF logs in CloudWatch Logs

Lab architecture. The echo function is an ALB target and doesn't run in the VPC.
The ALB is internal, because the default VPC in this account has no internet gateway attached and I didn't want to change the account's networking for a lab. WAF inspects internal and internet-facing ALBs the same way. The traffic function runs inside the VPC.
The 8 requests:
Case
Request
What it represents
legit-home
 GET /  with a browser User-Agent
Normal page view
legit-upload-12kb
 POST /api/reports , 12 KB JSON body
A report export or bulk save
legit-healthcheck-no-ua
 GET /health  with no User-Agent
An uptime monitor or script
legit-cms-save
 POST /cms/pages , JSON body containing  <script src=...> 
An editor embedding a widget
attack-lfi
 GET /download?file=../../../../etc/passwd 
Path traversal
attack-log4j
 X-Api-Version: ${jndi:ldap://...}  header
Log4Shell probe
attack-ssrf
 GET /fetch?url=http://169.254.169.254/latest/meta-data/iam/ 
Instance metadata SSRF
attack-xss
 GET /search?q=<script>alert(1)</script> 
Reflected XSS probe
Only the lab endpoint received these requests, and they were harmless strings sent to an echo function.

Deploy it yourself

I built the lab by hand first, then put it into a CloudFormation template so you can run it in a few minutes:  Ali-Bashir/aws-waf-count-to-block-lab . The template needs a VPC and two subnets in different Availability Zones. A  Stage  parameter moves the web ACL through the stages in this article:
Stage
Web ACL
 count 
Every rule in both managed groups overridden to Count (Steps 1 to 4)
 block-noisy-count 
Managed rules block, three noisy rules left on Count (Step 5)
 tuned 
Step 5 plus the three label-based exception rules (Step 6)
aws cloudformation deploy \
--stack-name waf-lab \
--template-file template.yaml \
--capabilities CAPABILITY_IAM \
--parameter-overrides VpcId=vpc-xxxxxxxx SubnetIds=subnet-aaaaaaaa,subnet-bbbbbbbb Stage=count
Invoke the traffic function to send the test requests, then redeploy with the next  Stage  value. I deployed the template and ran all three stages on 23 November 2026, and got the same results as the hand-built lab below. Creating the stack took about 6 minutes. Each stage change took about 10 seconds.

Step 1: Put every rule in Count

When you add a managed rule group, open its settings and choose Override all rule actions > Override to Count. Do this for every group you add.
Two settings on the same screens are worth noting:
  • Version. The console picks the group's default version. In production, pin a version so the rules don't change under you, and subscribe to the SNS topic shown on the rule group page for update notices.
  • Body size limit. For an ALB, WAF inspects only the first 8 KB of a request body. For CloudFront, API Gateway, Cognito and App Runner the default is 16 KB, and you can raise it to 64 KB ( AWS WAF docs ). This matters later.

Step 2: Turn on logging

Under Logging and metrics, enable logging to a CloudWatch Logs log group. The log group name has to start with  aws-waf-logs- . Set a retention period when you create the log group. The default is to keep logs forever.
The console also shows sampled requests: up to 100 requests that matched a rule and 100 that fell through to the default action, from the last three hours. There's a bigger catch for this process: sampled requests for Count rules inside rule groups don't appear in the web ACL view ( AWS WAF docs ). Those are exactly the matches you're tuning, so use the logs.

Step 3: Find out what would have been blocked

I sent the 8 requests three times. Every request returned 200, including the attacks, which is what Count mode should do.
Then I grouped the log records by the labels WAF added. This is the Logs Insights query I used in the lab:
parse @message /"X-Lab-Case","value":"(?<test_case>[^"]+)"/
| parse @message /"labels":\[(?<labels>[^\]]*)\]/
| stats count(*) as requests by test_case, labels
| sort test_case
Logs Insights results showing the label each test case received

Count mode, 24 requests (the query in the screenshot adds a time filter to show only the count-mode runs). Each attack matched the expected rule, and three legitimate requests matched rules too. Account ID redacted.
Request
Label added
attack-lfi
 core-rule-set:GenericLFI_QueryArguments 
attack-log4j
 known-bad-inputs:Log4JRCE_Header 
attack-ssrf
 core-rule-set:EC2MetaDataSSRF_QueryArguments  and  GenericRFI_QueryArguments 
attack-xss
 core-rule-set:CrossSiteScripting_QueryArguments 
legit-upload-12kb
 core-rule-set:SizeRestrictions_Body 
legit-healthcheck-no-ua
 core-rule-set:NoUserAgent_Header 
legit-cms-save
 core-rule-set:CrossSiteScripting_Body 
legit-home
none
On a real application you won't have a test-case header, so group by label and URI instead. I ran this version against the same logs:
fields httpRequest.uri as uri, httpRequest.clientIp as ip
| parse @message /"labels":\[(?<labels>[^\]]*)\]/
| filter labels like /awswaf:managed/
| stats count(*) as requests, count_distinct(ip) as clients by labels, uri
| sort requests desc
A label that appears on one URI from many clients is usually a false positive. A label spread across random URIs from a few clients is usually someone probing.
To see why a rule matched, open a single record. This is the relevant part of the CMS save:
"ruleGroupList": [{
"ruleGroupId": "AWS#AWSManagedRulesCommonRuleSet",
"nonTerminatingMatchingRules": [{
"ruleId": "CrossSiteScripting_BODY",
"action": "COUNT",
"overriddenAction": "BLOCK",
"ruleMatchDetails": [{
"conditionType": "XSS",
"location": "JSON_BODY",
"matchedData": ["<", "script"],
"matchedFieldName": "/html"
}]
}]
}],
"labels": [{"name": "awswaf:managed:aws:core-rule-set:CrossSiteScripting_Body"}]
 overriddenAction: BLOCK  tells you this request would have been blocked without the override.  matchedFieldName  tells you which JSON field triggered it.
Look at the casing. The rule is  CrossSiteScripting_BODY , but the label is  CrossSiteScripting_Body . The same goes for  NoUserAgent_Header ,  SizeRestrictions_Body  and  Log4JRCE_Header . When you write a label match rule, copy the label from your logs, not the rule name from the console.

Step 4: Decide what to do with each match

For each legitimate match, ask whether the request is genuinely legitimate and how narrowly you can describe it.
Rule
Legitimate traffic
Decision
 SizeRestrictions_BODY  (body over 8 KB)
 POST /api/reports  sends large JSON
Block everywhere except that exact path
 NoUserAgent_HEADER 
An uptime monitor calls  /health  with no User-Agent
Block everywhere except that exact path
 CrossSiteScripting_BODY 
Editors save HTML with embed scripts to  /cms/pages 
Block everywhere except that path, and tighten further in production (see below)
Fixing the client is sometimes better than writing an exception. If you control the monitor, give it a User-Agent and skip the exception entirely.
An ALB's own target health checks are sent by the load balancer nodes directly to the targets ( ELB docs ), so they aren't client requests arriving at the listener. A missing User-Agent on  /health  usually means an external monitor or an internal script.

Step 5: Switch to Block, but not the noisy rules

In the Core rule set, I chose Remove all overrides, then set just the three noisy rules back to Count. In Known bad inputs, I removed all overrides. AWS recommends switching rules from Count to Block one at a time, starting with the rule that has the fewest Count matches and the lowest false-positive risk ( re:Post ). On a real application, do that over days, not minutes.
Core rule set with only three rules overridden to Count

The Core rule set after this step: every rule uses its own action (Block) except NoUserAgent_HEADER, SizeRestrictions_BODY and CrossSiteScripting_BODY, which stay on Count. Account ID redacted.
I also added three probe requests. Each one sends the same "suspicious" content to a path that should not get an exception:
  •  POST /api/comments  with the CMS body containing  <script> 
  •  GET /admin  with no User-Agent
  •  POST /api/comments  with the 12 KB body
Result:
Requests
Status
4 legitimate
200
4 attacks
403
3 probes
200
The attacks are blocked and nothing legitimate broke. But the three rules on Count aren't protecting anything, on any path. Leaving a rule on Count isn't an exception. It turns the rule off everywhere.

Step 6: Add label-based exceptions

Each exception is a custom rule placed after the managed rule groups, because the label has to exist before the rule can check for it. Here's the XSS one, added through Add my own rules > Rule JSON editor:
{
"Name": "block-xss-body-except-cms",
"Priority": 2,
"Action": { "Block": {} },
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "block-xss-body-except-cms"
},
"Statement": {
"AndStatement": {
"Statements": [
{ "LabelMatchStatement": {
"Scope": "LABEL",
"Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting_Body" } },
{ "NotStatement": { "Statement": { "ByteMatchStatement": {
"SearchString": "/cms/pages",
"FieldToMatch": { "UriPath": {} },
"TextTransformations": [{ "Priority": 0, "Type": "NONE" }],
"PositionalConstraint": "STARTS_WITH" } } } }
]
}
}
}
The other two follow the same shape:
Rule
Label
Exception
 block-oversize-body-except-reports 
 ...:SizeRestrictions_Body 
URI path exactly  /api/reports 
 block-no-user-agent-except-health 
 ...:NoUserAgent_Header 
URI path exactly  /health 
Each exception rule uses 3 WCUs. The web ACL went from 900 to 909 WCUs, well under the 1,500 included in the base price.
Web ACL rules: two managed groups followed by three exception rules

The final web ACL. Order matters: the managed groups add labels at priority 0 and 1, and the exception rules read them at 2 to 4. Account ID redacted.

Step 7: Verify

The same 11 requests after adding the exceptions:
Traffic function response showing 200 for legitimate requests and 403 for attacks and probes

Final state: 4 legitimate requests allowed, 4 attacks and 3 probes blocked.
The logs show which rule made each decision:
fields terminatingRuleId, httpRequest.uri as uri
| filter action = "BLOCK"
| parse @message /"X-Lab-Case","value":"(?<test_case>[^"]+)"/
| stats count(*) as blocked by test_case, uri, terminatingRuleId
| sort test_case
Logs Insights: blocked requests grouped by terminating rule

Blocked requests by terminating rule across all runs: the managed groups blocked the attacks, and the new exception rules blocked the three probes. Account ID redacted.
One more detail from these logs: a Block is a terminating action, so WAF stops evaluating the request and rules after it never add their labels ( AWS WAF docs ). In Count mode the SSRF request carried two labels. After switching to Block it carried one, because the first matching rule ended evaluation. If you build dashboards or alerts on labels, test them in both modes.

What these exceptions don't protect against

Every exception is a hole, so be clear about the size of each one.
  • The CMS path now accepts script tags from anyone. In production, narrow it further: require the request to come from your editors' IP set or VPN, or limit it to authenticated admin sessions. And keep sanitizing HTML in the application. WAF is a layer, not the fix.
  • Bodies over 8 KB on  /api/reports  are only partly inspected. On an ALB, WAF's body rules see only the first 8 KB, and the Core rule set's body rules continue with what they can see rather than treating the oversize body as a match.  SizeRestrictions_BODY  was the rule that stopped oversize bodies, and this exception turns it off for this path. If that endpoint matters, put CloudFront in front (body inspection up to 64 KB, at extra cost) or validate the payload in the application.
  •  /health  accepts requests with no User-Agent. That's low risk on a static health endpoint. It isn't on an endpoint that does real work.
  • Managed rules change. A new version can match traffic that the old one didn't. Pin the version, and repeat this count-then-block process when you upgrade.

Cost

Prices are for US East (N. Virginia), taken from the AWS pricing pages on 23 November 2026. These are estimates, not a bill.
AWS WAF ( pricing ): $5 per web ACL per month, $1 per rule or rule group per month (both prorated hourly), and $0.60 per million requests. Bot Control, Account Takeover Prevention and Account Creation Fraud Prevention add their own subscription and request fees. The two groups used here don't. This lab's web ACL has 1 ACL, 2 managed groups and 3 custom rules: $10 per month before requests.
Logging. AWS WAF includes 500 MB of log ingestion per million WAF requests. Above that, CloudWatch charges vended log rates. The CloudWatch pricing page's examples use $0.50 per GB for the first 10 TB in this Region ( CloudWatch pricing ). Check the Pricing Calculator for your own volume. Stored logs cost $0.03 per GB-month.
My lab records averaged about 1.65 KB each. Real browser traffic carries more headers and cookies, so measure your own. Using 1.65 KB:
Monthly requests
WAF
Log volume
Billable log ingestion
Estimated total
10 million
$10 + $6 = $16
16.5 GB
16.5 GB minus 5 GB included = 11.5 GB, about $5.75
about $22 plus storage
100 million
$10 + $60 = $70
165 GB
165 GB minus 50 GB included = 115 GB, about $57.50
about $128 plus storage
Ways to reduce logging cost, and what each one costs you in visibility:
  • Shorter retention. Keep 30 to 90 days in CloudWatch for tuning and investigations, rather than forever.
  • Logging filters. You can keep or drop log records by rule action or by label, for example keeping only blocked and counted requests ( AWS WAF docs ). This cuts volume a lot, but you lose the allowed traffic you'd want when investigating an incident that got through.
  • S3 as the destination. This is cheaper for long-term storage, but you query it with Athena instead of Logs Insights.
The lab itself: the ALB costs about $0.54 a day ($0.0225 per hour) plus a few cents of LCU charges ( ELB pricing ), and the web ACL about $0.33 a day. The Lambda functions and log volume fall within the free tier. That's under $1 a day.

Production checklist

  • Run Count mode on real traffic for at least a week, so you see weekly jobs, batch exports and month-end traffic.
  • Get the matched URIs and payloads in front of the application owners. They know which requests are legitimate. You don't.
  • Switch rules to Block one at a time, starting with the ones that have the fewest matches.
  • Keep exceptions as narrow as possible: exact paths, specific methods, known source IPs.
  • Alert on a spike in blocked requests by rule, so a new release that starts tripping a rule doesn't fail silently for users.
  • Manage the web ACL as code (CloudFormation, Terraform or CDK) once it's tuned. Click-built exceptions are hard to review.
  • Pin managed rule versions and repeat the process before upgrading.

Cleanup

If you used the template, delete the stack:
aws cloudformation delete-stack --stack-name waf-lab
This removes everything, including the log group. Deletion can take several minutes, because Lambda releases the traffic function's VPC network interfaces slowly. If you uploaded the template in the console, CloudFormation also created a  cf-templates-  S3 bucket, which you can empty and delete.
If you built the lab by hand, delete:
  • the web ACL association, then the web ACL
  • the ALB and its target group
  • both Lambda functions and their execution roles
  • the security group
  • the  aws-waf-logs-  log group
The ALB and web ACL are the only items with meaningful hourly charges.

Takeaways

  • Start every managed rule group with Override all rule actions to Count, and turn on logging before anything else.
  • Group the logs by label and URI. One label on one URI from many clients usually means a false positive.
  • Copy labels from your logs. They don't use the same casing as the rule names.
  • Leaving a noisy rule on Count turns it off everywhere. A label match rule after the managed groups makes the exception only where it's needed.
  • Test exceptions with requests that shouldn't get through, not only the ones that should.
  • WAF logging costs real money at volume. Set retention on day one, and decide deliberately what you filter out.

References

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article