Protecting Web Applications with AWS WAF
This lesson explains how AWS WAF, a web application firewall, inspects HTTP and HTTPS requests to protected resources and allows, blocks or challenges them.
Learning outcomes
After completing this lesson, you will be able to:
- Configure web ACLs, rules and rule groups.
- Monitor WAF with metrics, sampled requests and logs.
- Audit a web ACL.
- Fix legitimate requests that are blocked.
Web ACLs, rules and rule groups
A web ACL is associated with one or more protected resources (CloudFront web ACLs are global and created in us-east-1; others are Regional). It contains rules evaluated in priority order, each with a statement and an action: Allow, Block, Count (record matches without acting), CAPTCHA or Challenge. The web ACL's default action applies when no rule terminates. Statements match IP sets, geographic origin, strings and regular expressions in parts of the request, size constraints, SQL injection and cross-site scripting patterns, labels added by other rules, and rate-based limits per IP or other keys. Managed rule groups from AWS (Core rule set, Known bad inputs, SQL database, IP reputation, anonymous IP, Bot Control, Account takeover prevention) and Marketplace sellers provide maintained protections; each consumes web ACL capacity units (WCUs).
The following diagram shows a request passing the rules in priority order.

WAF rule types
Logging and monitoring
WAF publishes CloudWatch metrics per rule and web ACL (AllowedRequests, BlockedRequests, CountedRequests, CaptchaRequests). Sampled requests in the console show recent matches. Full logging sends every request's details, including the terminating rule, labels and matched rules, to CloudWatch Logs (log group name beginning aws-waf-logs-), S3 or Firehose, with optional redaction of fields and filtering of which requests are logged. The WAF console's dashboards summarise traffic and top rules.
Auditing a web ACL
Auditing WAF in an account means checking that protection is attached and actually blocking what it should. The following checklist covers the common gaps.
- Is the web ACL associated with every public resource that should be protected (each ALB, API stage, distribution)?
- Are important rules in Count mode, or managed rule groups overridden to Count, so that they record but do not block?
- Is the default action Allow with sensible blocking rules, or Block with explicit allows, as intended?
- Is logging enabled, and do logs show the expected terminating rules for blocked requests?
- Are rate-based rules and IP sets current, and are managed rule group versions up to date?
- Do CloudFront or ALB origins accept traffic only from the protected path, so WAF cannot be bypassed?
AWS Config managed rules such as alb-waf-enabled, api-gw-associated-with-waf and cloudfront-associated-with-waf detect unprotected resources continuously.
Tuning WAF safely
Legitimate users blocked
After enabling the Core rule set, customers uploading documents receive 403 errors. WAF logs show the terminating rule AWSManagedRulesCommonRuleSet#SizeRestrictions_BODY, because uploads exceed the rule's body size limit. The operator sets that single rule to Count with a rule action override and adds a scoped-down rule that blocks large bodies on every path except /upload, so the rest of the managed rule group stays in Block mode.
How must the log group for WAF logs be named?
Show answer
It must start with aws-waf-logs-.
Exam Tips
Remember for the exam
- Web ACL rules: Allow, Block, Count, CAPTCHA, Challenge; the default action applies otherwise.
- Count mode records matches without blocking; check overrides during audits.
- WAF logs show the terminating rule; log groups must start with aws-waf-logs-.
- CloudFront web ACLs are created in us-east-1.
- Rate-based rules limit requests per IP or other keys.