
Day 43: AWS WAF and Shield – Protecting Web Applications from Attacks
Day 43 of my 90-day AWS challenge: how AWS WAF filters malicious web requests such as SQL injection and bots, how AWS Shield protects against DDoS attacks, and why new rules should start in Count mode before they block anything.
Starting week seven
The last six weeks covered building, hosting, and operating applications. Week seven is about protecting and recovering them. Applications that face the internet get attacked constantly: bots, scrapers, password guessing, SQL injection, and floods of traffic. Two services stand at the front door: AWS WAF and AWS Shield.
What is AWS WAF?
AWS WAF is a web application firewall. It looks at HTTP and HTTPS requests before they reach my application and decides whether to allow, block, or challenge them. It works at the application layer (Layer 7), so it can inspect URLs, headers, query strings, and request bodies.
What it can be attached to
- CloudFront distributions (Day 11)
- Application Load Balancers (Day 10)
- API Gateway REST APIs (Day 15)
- Cognito user pools (Day 22)
- AWS AppSync, and other supported services such as Amplify Hosting (Day 38) and App Runner
Key concepts
Concept | What it is |
|---|---|
Web ACL | The set of rules attached to a resource, evaluated in order |
Rule | A condition and an action, such as "if the request comes from this IP range, block it" |
Rule group | A reusable collection of rules |
Managed rule group | A ready-made group maintained by AWS or a vendor |
IP set | A list of IP addresses or ranges to match |
Rate-based rule | Counts requests from each client over a time window and acts when a limit is exceeded |
Default action | What happens when no rule matches (usually Allow) |
Rule actions
- Allow: let the request through
- Block: reject it with a response
- Count: don't change the outcome, just record that the rule matched
- CAPTCHA and Challenge: ask the client to prove it is a person or a real browser
Useful managed rule groups
AWS offers managed groups that cover common problems, for example:
- Core rule set: general protection against common web threats from the OWASP Top 10
- Known bad inputs: patterns known to exploit vulnerabilities
- SQL database: blocks SQL injection attempts, which relate to the SQL I use with RDS (Day 6)
- IP reputation: blocks addresses known for bad behavior
- Bot Control: identifies and manages bots (extra cost)
They save me from writing and updating signatures myself.
Common protections
- Rate limiting per client IP, to slow down password guessing and scraping
- Geographic rules, to allow or block requests from certain countries
- Header or path rules, for example blocking access to an admin path from outside my IP range
- Request size limits
Start in Count mode
A new rule can accidentally block real users. The safe way to roll out is:
- Add the rule in Count mode
- Watch the sampled requests and logs to see what it would have blocked
- Fix false positives, for example by adding an exception
- Switch the rule to Block
Logging and monitoring
- Sampled requests in the console show recent matches
- WAF logs can go to CloudWatch Logs, S3, or Firehose (Day 31), where Athena (Day 29) can query them
- CloudWatch metrics (Day 9) track allowed, blocked, and counted requests per rule
- CloudTrail (Day 20) records who changed the web ACL
AWS Shield
Shield protects against DDoS (distributed denial-of-service) attacks, which flood a service with traffic to take it down.
| Shield Standard | Shield Advanced |
|---|---|---|
Cost | Included at no extra charge | Paid subscription |
Coverage | Common network and transport layer (Layers 3 and 4) attacks, on all AWS customers | Larger, more sophisticated attacks on protected resources, with more detection |
Extras | Automatic | Access to the AWS Shield Response Team, cost protection for attack-related scaling charges, and WAF integration |
Shield Standard is on automatically. Shield Advanced has a significant monthly fee and a long commitment, so it is meant for large, business-critical applications, and I don't need it for practice.
Related services
- AWS Firewall Manager: applies WAF, Shield, and other rules across many accounts in an organization (Day 40)
- AWS Network Firewall: a managed firewall for network traffic inside and between VPCs (Day 41)
- Security groups and NACLs (Day 5) still control which ports and addresses can connect
Defense in layers
- Shield absorbs network-level floods
- CloudFront serves cached content and spreads load (Day 11)
- WAF filters malicious requests
- Load balancer and Auto Scaling handle legitimate traffic (Day 10)
- Application code still validates input, uses parameterized queries, and enforces authorization, because WAF is not a substitute for secure code
Cost
WAF is billed by the number of web ACLs, the number of rules, and the number of requests inspected, and some managed groups, such as Bot Control, cost extra. Check the pricing page, and set a budget (Day 26).
How it connects to earlier days
- Day 10, 11, and 15: the places a web ACL is attached
- Day 22: protecting the Cognito sign-in with rate limits
- Day 31 and 29: logs through Firehose to S3, queried with Athena
- Day 20: CloudTrail for changes, and CloudWatch for metrics
What I practiced today
- Created a web ACL and attached it to one of my own test resources
- Added the core rule set and the SQL database managed rule groups in Count mode
- Added a rate-based rule with a low limit
- Sent a few test requests, including a harmless SQL-injection-style query string, to my own resource only, and found them in the sampled requests
- Switched one rule to Block and confirmed the response
- Deleted the web ACL afterwards
Key takeaways
- WAF filters web requests, and Shield defends against DDoS floods
- Roll out new rules in Count mode first, then block
- Managed rule groups give broad protection quickly, but secure code is still essential
- Don't subscribe to Shield Advanced for practice, and delete practice web ACLs because they bill monthly
Up next: Day 44
AWS Backup and disaster recovery: RPO, RTO, and recovery strategies.
Learning AWS too? Follow along and share what you're building. #90DaysOfAWS
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article