WAF, Shield, and Network Firewall
Block OWASP top-10 attacks with AWS WAF, protect against DDoS with Shield Standard and Advanced, and deploy a stateful Network Firewall in your VPC.
WAF, Shield, and Network Firewall is a free AWS Solutions Architect lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Network Security Defence in Depth
Protecting your applications from network-based attacks requires multiple layers of defence. AWS provides three complementary services: AWS WAF (Web Application Firewall) filters layer-7 HTTP traffic based on rules to block application-layer attacks. AWS Shield protects against DDoS (Distributed Denial of Service) attacks at layers 3 and 4. AWS Network Firewall is a stateful network firewall for VPC-level traffic inspection and filtering. Together, they address different threat vectors and are typically deployed together for comprehensive protection.
# Layer coverage:
# Network Firewall: Layer 3-7 VPC traffic (stateful)
# Shield Standard: Layer 3-4 DDoS (automatic, free)
# Shield Advanced: Layer 3-7 DDoS + response team
# WAF: Layer 7 HTTP/HTTPS (application attacks)
# Typical deployment:
# Internet -> CloudFront+WAF -> ALB+WAF -> EC2/ECS
# Network Firewall in VPC for egress/lateral inspection
# Shield protects all traffic automaticallyAWS WAF: Web Application Firewall
AWS WAF filters HTTP/HTTPS requests based on rules you define. WAF integrates with CloudFront, ALB, API Gateway, AppSync, and Cognito. Rules can match on: IP address sets (block/allow specific IPs), geo-match (block requests from specific countries), rate-based rules (block IPs exceeding a request rate — flood protection), managed rule groups (pre-built rules for OWASP top 10, AWS Threat Intel, Bot Control), and custom rules (match on any HTTP component). WAF ACLs (Web ACL) contain rules and apply to one or more resources.
# Create WAF Web ACL
aws wafv2 create-web-acl \
--name 'prod-web-acl' \
--scope CLOUDFRONT \
--region us-east-1 \
--default-action Allow={} \
--rules '[{
"Name": "AWSManagedRulesCommonRuleSet",
"Priority": 1,
"OverrideAction": {"None": {}},
"Statement": {
"ManagedRuleGroupStatement": {
"VendorName": "AWS",
"Name": "AWSManagedRulesCommonRuleSet"
}
},
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "CommonRuleSet"
}
}]' \
--visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName=web-acl-metricsWAF Managed Rule Groups
AWS Managed Rule Groups are pre-built WAF rule sets maintained by AWS that protect against common threats without requiring you to write individual rules. Key groups: AWSManagedRulesCommonRuleSet — protects against OWASP top 10 (SQL injection, XSS, RFI, LFI). AWSManagedRulesKnownBadInputsRuleSet — blocks known bad input patterns. AWSManagedRulesAmazonIpReputationList — blocks IPs with bad reputation (botnets, compromised). AWSManagedRulesBotControlRuleSet — detects and blocks scraper bots and automated browsers. Most WAF deployments start with these managed groups before adding custom rules.
# Add IP reputation list managed rule group
aws wafv2 update-web-acl \
--name 'prod-web-acl' \
--scope CLOUDFRONT \
--id <acl-id> \
--lock-token <lock-token> \
--rules '[{
"Name": "AWSManagedRulesAmazonIpReputationList",
"Priority": 0,
"OverrideAction": {"None": {}},
"Statement": {
"ManagedRuleGroupStatement": {
"VendorName": "AWS",
"Name": "AWSManagedRulesAmazonIpReputationList"
}
}
}, ...existing_rules...]'WAF Rate-Based Rules
Rate-based rules in AWS WAF automatically block IP addresses that exceed a configurable request rate threshold within a 5-minute window. This protects against: HTTP flood attacks (overwhelming your servers with requests), brute force attacks (many login attempts), and API abuse (scraping or enumeration). You can aggregate by IP, by IP + request path (rate-limit a specific endpoint like /login), or by custom headers. Blocked IPs are automatically unblocked when their rate drops below the threshold — no manual intervention needed.
# Create rate-based rule for login endpoint
aws wafv2 update-web-acl \
--rules '[{
"Name": "RateLimitLogin",
"Priority": 2,
"Action": {"Block": {}},
"Statement": {
"RateBasedStatement": {
"Limit": 100,
"AggregateKeyType": "IP",
"ScopeDownStatement": {
"ByteMatchStatement": {
"SearchString": "/api/login",
"FieldToMatch": {"UriPath": {}},
"TextTransformations": [{"Priority": 0, "Type": "LOWERCASE"}],
"PositionalConstraint": "STARTS_WITH"
}
}
}
}
}]'AWS Shield Standard and Advanced
AWS Shield Standard is automatic DDoS protection included for all AWS customers at no additional cost. It protects against the most common layer 3 (network) and layer 4 (transport) DDoS attacks — SYN floods, UDP floods, reflection attacks. AWS Shield Advanced provides enhanced protection for layer 3, 4, and 7 attacks on EC2, ALB, CloudFront, Global Accelerator, and Route 53. Shield Advanced includes: AWS DDoS Response Team (DRT) support, cost protection (DDoS-related scaling charges are refunded), real-time metrics, and advanced attack forensics. Shield Advanced costs $3,000/month plus a data transfer fee.
# Enable Shield Advanced protection on ALB
aws shield create-protection \
--name 'prod-alb-protection' \
--resource-arn arn:aws:elasticloadbalancing:us-east-1:123:loadbalancer/app/prod-alb/abc
# Associate with a WAF Web ACL for layer-7 protection
aws shield associate-drt-log-bucket \
--log-bucket my-shield-logs
# With Shield Advanced:
# - DDoS events detected and mitigated automatically
# - DRT can tune WAF rules during active attacks
# - Real-time CloudWatch dashboard
# - AWS will refund EC2/ELB/CloudFront scaling costs from DDoSAWS Network Firewall
AWS Network Firewall is a stateful, managed network firewall service deployed in your VPC to inspect and filter traffic. Unlike Security Groups (stateful, resource-level) and NACLs (stateless, subnet-level), Network Firewall provides: Deep packet inspection (DPI), stateful connection tracking, domain filtering (block by domain name or pattern), IPS (Intrusion Prevention System) rules using Suricata-compatible rule format, and egress filtering (control what your EC2 instances can call on the internet). Deploy Network Firewall in a dedicated firewall subnet in each AZ.
# Create Network Firewall
aws network-firewall create-firewall \
--firewall-name prod-vpc-firewall \
--firewall-policy-arn arn:aws:network-firewall:us-east-1:123:firewall-policy/my-policy \
--vpc-id vpc-12345 \
--subnet-mappings '[{"SubnetId":"subnet-firewall-AZ1"},{"SubnetId":"subnet-firewall-AZ2"}]'
# Network Firewall topology:
# Internet -> IGW -> Firewall subnet (Network FW) -> App subnet
# Egress: App subnet -> Firewall subnet (Network FW) -> IGW -> InternetNetwork Firewall Rule Groups
Network Firewall uses rule groups to define filtering logic. Stateless rule groups process packets without tracking connections — similar to NACLs but more flexible. Stateful rule groups track TCP connection state and inspect complete HTTP/TLS sessions. You can write rules in three ways: 5-tuple rules (source IP, destination IP, protocol, source port, destination port), domain list rules (allow or deny by FQDN), and Suricata-compatible IPS rules (the most powerful — pattern matching, protocol inspection). AWS provides managed rule groups for common threats.
# Create domain list rule group (egress filtering)
aws network-firewall create-rule-group \
--rule-group-name 'allow-egress-domains' \
--type STATEFUL \
--capacity 100 \
--rules-source '{
"RulesSourceList": {
"Targets": [
"amazonaws.com",
"example.com",
"*.npmjs.com"
],
"TargetTypes": ["HTTP_HOST","TLS_SNI"],
"GeneratedRulesType": "ALLOWLIST"
}
}'
# Block all other egress traffic by default
# Prevents EC2 from calling malicious external domainsComparing WAF, Shield, and Network Firewall
The three services address different use cases and are complementary, not alternatives: WAF — layer-7 HTTP inspection, blocks application attacks (SQLi, XSS), rate limiting, bot control. Deployed at CloudFront or ALB. Shield — DDoS mitigation, protects infrastructure from volumetric attacks. Shield Standard is always on; Advanced adds team support. Network Firewall — layer 3-7 VPC traffic control, stateful inspection, domain filtering, IPS/IDS. Deployed inside VPC subnets. Use all three together: Network Firewall controls VPC-level traffic, WAF filters application requests, Shield mitigates DDoS.
# Comparison table:
# Service Scope Layer Use Case
# AWS WAF Edge/ALB 7 App attacks, rate limits, bots
# Shield Standard All 3-4 Auto DDoS mitigation (free)
# Shield Advanced All 3-7 Enhanced DDoS + DRT support
# Network Firewall VPC 3-7 Stateful inspection, IPS, egress
# SAA-C03 exam keywords:
# 'SQL injection protection' -> WAF
# 'DDoS protection' -> Shield
# 'Block EC2 from calling external IPs' -> Network Firewall
# 'Block requests from country X' -> WAF geo-matchWAF Logging and Analysis
WAF can log all sampled requests (1 in 5) or all requests to CloudWatch Logs, S3, or Kinesis Data Firehose. Logs include the full request headers, the IP address, country, which rules matched, and the action taken (ALLOW/BLOCK/COUNT). Use WAF logs to: Investigate attacks — see exactly what requests were blocked. Tune rules — identify false positives (legitimate requests being blocked) and add exceptions. Detect new threats — patterns in blocked requests may reveal new attack vectors. Enable COUNT mode for new rules before switching to BLOCK to validate they don't block legitimate traffic.
# Enable WAF logging to Kinesis Firehose
aws wafv2 put-logging-configuration \
--logging-configuration '{
"ResourceArn": "arn:aws:wafv2:us-east-1:123:global/webacl/prod-web-acl/abc",
"LogDestinationConfigs": [
"arn:aws:firehose:us-east-1:123:deliverystream/waf-logs"
],
"LoggingFilter": {
"DefaultBehavior": "KEEP",
"Filters": [{
"Behavior": "KEEP",
"Conditions": [{"ActionCondition":{"Action":"BLOCK"}}],
"Requirement": "MEETS_ANY"
}]
}
}'WAF Deployment Architecture Patterns
Deploying AWS WAF correctly requires understanding where to attach it in your architecture. For internet-facing applications, attach WAF to CloudFront so inspection happens at the edge before traffic reaches your origin — this blocks attacks before they consume origin bandwidth. For internal APIs or when CloudFront is not used, attach WAF to the ALB. For APIs exposed via API Gateway, WAF can be attached at the API Gateway level. You can attach WAF to multiple resources simultaneously — a CloudFront distribution AND the ALB behind it — for defence in depth, though this doubles inspection costs.
# WAF attachment points:
# 1. CloudFront distribution (global edge, CLOUDFRONT scope)
aws wafv2 associate-web-acl \
--web-acl-arn arn:aws:wafv2:us-east-1:123:global/webacl/my-acl/abc \
--resource-arn arn:aws:cloudfront::123:distribution/EXAMPLEID
# 2. ALB (regional, REGIONAL scope)
aws wafv2 associate-web-acl \
--web-acl-arn arn:aws:wafv2:us-east-1:123:regional/webacl/my-acl/xyz \
--resource-arn arn:aws:elasticloadbalancing:us-east-1:123:loadbalancer/app/my-alb/abc
# 3. API Gateway REST API
# 4. AppSync GraphQL API
# 5. Amazon Cognito User PoolFirewall Manager for Multi-Account WAF
AWS Firewall Manager centralises WAF, Shield Advanced, Network Firewall, and security group policies across all accounts in an AWS Organization. Define WAF rules once in Firewall Manager and they automatically apply to all ALBs, CloudFront distributions, and API Gateways in all member accounts — including newly created resources. If a member account deploys a new ALB, Firewall Manager automatically associates the WAF Web ACL. This ensures consistent security policy enforcement across the organisation without relying on individual teams to configure WAF correctly.
# Create Firewall Manager WAF policy
aws fms put-policy \
--policy '{
"PolicyName": "org-wide-waf-policy",
"SecurityServicePolicyData": {
"Type": "WAFV2",
"ManagedServiceData": "{\"type\":\"WAFV2\",\"preProcessRuleGroups\":[{\"managedRuleGroupIdentifier\":{\"vendorName\":\"AWS\",\"managedRuleGroupName\":\"AWSManagedRulesCommonRuleSet\"},\"ruleGroupArn\":null,\"overrideAction\":{\"type\":\"NONE\"},\"excludeRules\":[],\"ruleGroupType\":\"ManagedRuleGroup\"}]}"
},
"ResourceType": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"IncludeMap": {"ACCOUNT": []},
"ExcludeResourceTags": false,
"RemediationEnabled": true
}'Quick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you learned: AWS WAF filters layer-7 HTTP traffic to block SQL injection, XSS, bots, and rate-limit abusive IPs, Shield Standard provides automatic layer-3/4 DDoS protection while Shield Advanced adds response team support and cost protection, and Network Firewall provides stateful VPC-level traffic inspection with domain filtering and IPS rules. Firewall Manager enforces policies across all accounts in an Organisation. Congratulations on completing the Security Architecture section!
Frequently asked questions
Is the “WAF, Shield, and Network Firewall” lesson free?
Yes — the full text of “WAF, Shield, and Network Firewall” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “WAF, Shield, and Network Firewall”?
Block OWASP top-10 attacks with AWS WAF, protect against DDoS with Shield Standard and Advanced, and deploy a stateful Network Firewall in your VPC. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “WAF, Shield, and Network Firewall” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- KMS, ACM, and Encryption Patterns
- GuardDuty, Inspector, and Macie
- Secrets Manager and Parameter Store
- WAF, Shield, and Network Firewall