Skip to content

Network Security (WAF, Shield, Firewall Manager)


AWS provides multiple layers of network security to protect your applications from common web exploits and DDoS attacks.

AWS Network Security Overview
+------------------------------------------------------------------+
| |
| +------------------------+ |
| | Network Security | |
| +------------------------+ |
| | |
| +---------------------+---------------------+ |
| | | | |
| v v v |
| +----------+ +----------+ +----------+ |
| | WAF | | Shield | | Firewall | |
| | | | | | Manager | |
| | - Web | | - DDoS | | - Central| |
| | Attacks| | Protect| | Manage | |
| | - Rules | | - Shield | | - Rules | |
| | - Bot | | Advanced| | - Policies| |
| | Control| | | | | |
| +----------+ +----------+ +----------+ |
| |
+------------------------------------------------------------------+
FeatureWAFShield StandardShield AdvancedFirewall Manager
Protection TypeWeb exploitsDDoSDDoS + SupportCentral management
CostPer rule + requestFree$3,000/monthBased on policies
LayerLayer 7Layer 3/4Layer 3/4/7Management
ScopeWeb appsAll AWSProtected resourcesOrganization-wide

AWS WAF Architecture
+------------------------------------------------------------------+
| |
| Internet |
| | |
| v |
| +----------------+ |
| | CloudFront | |
| | or ALB | |
| +----------------+ |
| | |
| v |
| +----------------+ |
| | AWS WAF | |
| +----------------+ |
| | |
| +-------------------+-------------------+ |
| | | | |
| v v v |
| +----------+ +----------+ +----------+ |
| | Web ACL | | Rule | | IP Set | |
| | | | Groups | | | |
| | - Default| | | | - Allow | |
| | Action | | - Managed| | - Block | |
| | - Rules | | - Custom | | Lists | |
| +----------+ +----------+ +----------+ |
| |
+------------------------------------------------------------------+
WAF Components
+------------------------------------------------------------------+
| |
| Web ACL (Access Control List) |
| +------------------------------------------------------------+ |
| | - Central resource for WAF configuration | |
| | - Contains rules and rule groups | |
| | - Has default action (allow or block) | |
| | - Associated with CloudFront, ALB, or API Gateway | |
| +------------------------------------------------------------+ |
| |
| Rules |
| +------------------------------------------------------------+ |
| | - Define matching criteria and actions | |
| | - Can be custom or managed | |
| | - Actions: Allow, Block, Count, Captcha | |
| +------------------------------------------------------------+ |
| |
| Rule Groups |
| +------------------------------------------------------------+ |
| | - Collection of rules | |
| | - Managed rule groups (AWS, AWS Marketplace) | |
| | - Custom rule groups | |
| +------------------------------------------------------------+ |
| |
| IP Sets |
| +------------------------------------------------------------+ |
| | - List of IP addresses/ranges | |
| | - Used for allow/block lists | |
| | - Up to 10,000 IP addresses per set | |
| +------------------------------------------------------------+ |
| |
| Regex Patterns |
| +------------------------------------------------------------+ |
| | - Regular expression patterns | |
| | - Used for complex matching | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
WAF Rule Types
+------------------------------------------------------------------+
| |
| Managed Rule Groups |
| +------------------------------------------------------------+ |
| | | |
| | AWS Managed Rules: | |
| | +------------------------------------------------------+ | |
| | | - AWSManagedRulesCommonRuleSet (Core rule set) | | |
| | | - AWSManagedRulesAnonymousIpList (Anonymous IP) | | |
| | | - AWSManagedRulesSQLiRuleSet (SQL injection) | | |
| | | - AWSManagedRulesLinuxRuleSet (Linux specific) | | |
| | | - AWSManagedRulesUnixRuleSet (Unix specific) | | |
| | | - AWSManagedRulesWindowsRuleSet (Windows specific) | | |
| | +------------------------------------------------------+ | |
| | | |
| | Vendor Managed Rules (AWS Marketplace): | |
| | +------------------------------------------------------+ | |
| | | - Fortinet, Imperva, Trend Micro, etc. | | |
| | +------------------------------------------------------+ | |
| | | |
| +------------------------------------------------------------+ |
| |
| Custom Rules |
| +------------------------------------------------------------+ |
| | | |
| | Rate-based Rules: | |
| | +------------------------------------------------------+ | |
| | | - Limit requests from IP address | | |
| | | - Configurable rate (100-2,000,000 requests/5min) | | |
| | +------------------------------------------------------+ | |
| | | |
| | Regular Rules: | |
| | +------------------------------------------------------+ | |
| | | - IP match (IP sets) | | |
| | | - Geographic match (country codes) | | |
| | | - String match (query string, headers, body) | | |
| | | - Regex match (pattern matching) | | |
| | | - Size constraint (request size) | | |
| | | - SQL injection match | | |
| | | - XSS match | | |
| | +------------------------------------------------------+ | |
| | | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
WAF Rule Evaluation Flow
+------------------------------------------------------------------+
| |
| Incoming Request |
| | |
| v |
| +------------------------+ |
| | Check Web ACL Rules | |
| +------------------------+ |
| | |
| +------------------+------------------+ |
| | | | |
| v v v |
| +--------+ +--------+ +--------+ |
| | Rule 1 | | Rule 2 | | Rule N | |
| | Match? | | Match? | | Match? | |
| +--------+ +--------+ +--------+ |
| | | | |
| v v v |
| +--------+ +--------+ +--------+ |
| | Action | | Action | | Action | |
| +--------+ +--------+ +--------+ |
| | | | |
| +------------------+------------------+ |
| | |
| v |
| +------------------------+ |
| | Any Block Action? | |
| +------------------------+ |
| | | |
| Yes No |
| | | |
| v v |
| +----------+ +------------------+ |
| | BLOCK | | Default Action | |
| | (403) | | (Allow/Block) | |
| +----------+ +------------------+ |
| |
+------------------------------------------------------------------+
Terminal window
# Create IP set
aws wafv2 create-ip-set \
--name "BlockedIPs" \
--scope REGIONAL \
--ip-address-version IPV4 \
--addresses "192.0.2.0/24" "203.0.113.0/24"
# Create web ACL
aws wafv2 create-web-acl \
--name "MyWebACL" \
--scope REGIONAL \
--default-action Allow={} \
--rules file://rules.json
# List web ACLs
aws wafv2 list-web-acls \
--scope REGIONAL
# Get web ACL
aws wafv2 get-web-acl \
--name "MyWebACL" \
--scope REGIONAL \
--id "abc123"
# Associate web ACL with ALB
aws wafv2 associate-web-acl \
--web-acl-arn "arn:aws:wafv2:..." \
--resource-arn "arn:aws:elasticloadbalancing:..."
# Create rule group
aws wafv2 create-rule-group \
--name "MyRuleGroup" \
--scope REGIONAL \
--capacity 500

AWS Shield Overview
+------------------------------------------------------------------+
| |
| +------------------------+ |
| | AWS Shield | |
| +------------------------+ |
| | |
| +---------------------+---------------------+ |
| | | |
| v v |
| +----------+ +----------+ |
| | Shield | | Shield | |
| | Standard | | Advanced | |
| | | | | |
| | - FREE | | - $3,000/mo| |
| | - Layer | | - Layer | |
| | 3/4 | | 3/4/7 | |
| | - Auto | | - DDoS | |
| | Enabled| | Response| |
| +----------+ | - Support| |
| +----------+ |
| |
+------------------------------------------------------------------+
Shield Standard vs Advanced
+------------------------------------------------------------------+
| |
| Feature | Standard | Advanced |
| -----------------------|-----------------|---------------------- |
| Cost | FREE | $3,000/month + usage |
| Layer 3/4 Protection | Yes | Yes |
| Layer 7 Protection | No | Yes (with WAF) |
| DDoS Response Team | No | Yes (24/7) |
| Cost Protection | No | Yes |
| Visibility | Basic | Advanced |
| Proactive Engagement | No | Yes |
| Auto Enrollment | Yes (all AWS) | Manual |
| |
+------------------------------------------------------------------+
Shield Advanced Architecture
+------------------------------------------------------------------+
| |
| Internet |
| | |
| v |
| +----------------+ |
| | AWS Shield | |
| | Advanced | |
| +----------------+ |
| | |
| +-------------------+-------------------+ |
| | | | |
| v v v |
| +----------+ +----------+ +----------+ |
| |CloudFront| | ALB | | Route 53 | |
| +----------+ +----------+ +----------+ |
| | | | |
| +-------------------+-------------------+ |
| | |
| v |
| +----------------+ |
| | DDoS Response | |
| | Team (DRT) | |
| +----------------+ |
| | |
| v |
| +----------------+ |
| | AWS Support | |
| | Center | |
| +----------------+ |
| |
+------------------------------------------------------------------+
Shield Advanced Protected Resources
+------------------------------------------------------------------+
| |
| Supported Resources |
| +------------------------------------------------------------+ |
| | | |
| | +------------------+ +------------------+ | |
| | | Amazon CloudFront| | Route 53 | | |
| | | (Global) | | (Global) | | |
| | +------------------+ +------------------+ | |
| | | |
| | +------------------+ +------------------+ | |
| | | Application Load | | Global Accelerator| | |
| | | Balancer | | | | |
| | +------------------+ +------------------+ | |
| | | |
| | +------------------+ +------------------+ | |
| | | Network Load | | AWS Elastic IP | | |
| | | Balancer | | | | |
| | +------------------+ +------------------+ | |
| | | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Terminal window
# Create protection (Shield Advanced)
aws shield create-protection \
--name "MyProtection" \
--resource-arn "arn:aws:cloudfront::..."
# List protections
aws shield list-protections
# Describe protection
aws shield describe-protection \
--protection-id "abc123"
# Describe DDoS attack
aws shield describe-attack \
--attack-id "attack-123"
# List attacks
aws shield list-attacks \
--start-time From=2024-01-01T00:00:00Z,To=2024-01-31T23:59:59Z
# Engage DRT (DDoS Response Team)
aws shield create-drt-access \
--role-arn "arn:aws:iam::..." \
--log-s3-bucket "my-ddos-logs"

AWS Firewall Manager Architecture
+------------------------------------------------------------------+
| |
| +------------------------+ |
| | Firewall Manager | |
| +------------------------+ |
| | |
| +---------------------+---------------------+ |
| | | | |
| v v v |
| +----------+ +----------+ +----------+ |
| | WAF | | Shield | | Security | |
| | Policies | | Advanced | | Groups | |
| | | | Policies | | | |
| +----------+ +----------+ +----------+ |
| | | | |
| v v v |
| +----------+ +----------+ +----------+ |
| | Apply to | | Apply to | | Apply to | |
| | All | | Protected| | VPCs | |
| | Accounts | | Resources| | | |
| +----------+ +----------+ +----------+ |
| |
+------------------------------------------------------------------+
Firewall Manager Policy Types
+------------------------------------------------------------------+
| |
| WAF Policy |
| +------------------------------------------------------------+ |
| | - Deploy WAF rules across accounts | |
| | - Ensure consistent web protection | |
| | - Automatic remediation of non-compliant resources | |
| +------------------------------------------------------------+ |
| |
| Shield Advanced Policy |
| +------------------------------------------------------------+ |
| | - Auto-enroll resources in Shield Advanced | |
| | - Apply protection to new resources | |
| | - Ensure DDoS protection across organization | |
| +------------------------------------------------------------+ |
| |
| Security Group Policy |
| +------------------------------------------------------------+ |
| | - Manage security groups across accounts | |
| | - Enforce common security group rules | |
| | - Audit and remediate non-compliant rules | |
| +------------------------------------------------------------+ |
| |
| Network Firewall Policy |
| +------------------------------------------------------------+ |
| | - Deploy AWS Network Firewall rules | |
| | - Centralized network traffic inspection | |
| | - Intrusion prevention and detection | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Firewall Manager Policy Workflow
+------------------------------------------------------------------+
| |
| 1. Create Policy |
| +------------------------------------------------------------+ |
| | - Define policy type (WAF, Shield, Security Group) | |
| | - Configure rules and settings | |
| | - Set remediation action | |
| +------------------------------------------------------------+ |
| | |
| v |
| 2. Define Scope |
| +------------------------------------------------------------+ |
| | - Select accounts (all or specific) | |
| | - Select resources (by tags or types) | |
| | - Exclude specific resources | |
| +------------------------------------------------------------+ |
| | |
| v |
| 3. Apply Policy |
| +------------------------------------------------------------+ |
| | - Automatic deployment to matching resources | |
| | - Continuous compliance monitoring | |
| | - Automatic remediation of violations | |
| +------------------------------------------------------------+ |
| | |
| v |
| 4. Monitor and Audit |
| +------------------------------------------------------------+ |
| | - View compliance status | |
| | - Review violations | |
| | - Update policy as needed | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

AWS Network Firewall Architecture
+------------------------------------------------------------------+
| |
| Internet |
| | |
| v |
| +----------------+ |
| | Internet | |
| | Gateway | |
| +----------------+ |
| | |
| v |
| +----------------+ |
| | Network | |
| | Firewall | |
| | Endpoint | |
| +----------------+ |
| | |
| +-------------------+-------------------+ |
| | | |
| v v |
| +----------+ +----------+ |
| | Public | | Private | |
| | Subnets | | Subnets | |
| +----------+ +----------+ |
| |
+------------------------------------------------------------------+
Network Firewall Components
+------------------------------------------------------------------+
| |
| Firewall Policy |
| +------------------------------------------------------------+ |
| | - Collection of rule groups | |
| | - Stateless and stateful rule groups | |
| | - Default actions | |
| +------------------------------------------------------------+ |
| |
| Rule Groups |
| +------------------------------------------------------------+ |
| | | |
| | Stateless Rule Groups: | |
| | +------------------------------------------------------+ | |
| | | - Process first, before stateful rules | | |
| | | - Use 5-tuple matching (src, dst, port, protocol) | | |
| | | - Actions: Pass, Drop, Forward to stateful | | |
| | +------------------------------------------------------+ | |
| | | |
| | Stateful Rule Groups: | |
| | +------------------------------------------------------+ | |
| | | - Deep packet inspection | | |
| | | - Suricata-compatible rules | | |
| | | - Domain list filtering | | |
| | | - Intrusion prevention (IPS) | | |
| | +------------------------------------------------------+ | |
| | | |
| +------------------------------------------------------------+ |
| |
| Firewall Endpoint |
| +------------------------------------------------------------+ |
| | - Deployed in subnet | |
| | - Processes traffic | |
| | - Scales automatically | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

WAF Security Best Practices
+------------------------------------------------------------------+
| |
| 1. Start with managed rule groups |
| +------------------------------------------------------------+ |
| | - Use AWS managed rules as baseline | |
| | - Add custom rules for specific needs | |
| +------------------------------------------------------------+ |
| |
| 2. Use COUNT mode for testing |
| +------------------------------------------------------------+ |
| | - Test rules in COUNT mode first | |
| | - Analyze logs before blocking | |
| | - Switch to BLOCK after validation | |
| +------------------------------------------------------------+ |
| |
| 3. Implement rate limiting |
| +------------------------------------------------------------+ |
| | - Protect against brute force attacks | |
| | - Set appropriate thresholds | |
| +------------------------------------------------------------+ |
| |
| 4. Enable logging |
| +------------------------------------------------------------+ |
| | - Send logs to S3, CloudWatch, or Kinesis | |
| | - Analyze for threats and tuning | |
| +------------------------------------------------------------+ |
| |
| 5. Use CAPTCHA for suspicious requests |
| +------------------------------------------------------------+ |
| | - Challenge suspicious traffic | |
| | - Reduce false positives | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Shield Best Practices
+------------------------------------------------------------------+
| |
| 1. Enable Shield Advanced for critical applications |
| +------------------------------------------------------------+ |
| | - Get 24/7 DDoS response team support | |
| | - Protect against large-scale attacks | |
| +------------------------------------------------------------+ |
| |
| 2. Configure proactive engagement |
| +------------------------------------------------------------+ |
| | - DRT can respond during attacks | |
| | - Enable access to your environment | |
| +------------------------------------------------------------+ |
| |
| 3. Set up health checks |
| +------------------------------------------------------------+ |
| | - Route 53 health checks for automatic failover | |
| | - CloudWatch alarms for monitoring | |
| +------------------------------------------------------------+ |
| |
| 4. Enable DDoS detection metrics |
| +------------------------------------------------------------+ |
| | - Monitor DDoSAttackIO and DDoSAttackPackets | |
| | - Set up alerts for attack detection | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

Integrated Security Architecture
+------------------------------------------------------------------+
| |
| Internet |
| | |
| v |
| +----------------+ |
| | AWS Shield | |
| | Standard | |
| | (Layer 3/4) | |
| +----------------+ |
| | |
| v |
| +----------------+ |
| | CloudFront | |
| | Distribution | |
| +----------------+ |
| | |
| v |
| +----------------+ |
| | AWS WAF | |
| | (Layer 7) | |
| +----------------+ |
| | |
| v |
| +----------------+ |
| | Application | |
| | Load Balancer | |
| +----------------+ |
| | |
| v |
| +----------------+ |
| | EC2 / ECS / | |
| | Lambda | |
| +----------------+ |
| |
+------------------------------------------------------------------+

Common WAF Issues
+------------------------------------------------------------------+
| |
| Issue 1: Legitimate traffic being blocked |
| +------------------------------------------------------------+ |
| | Cause: Overly restrictive rules | |
| | Solution: Use COUNT mode to test, adjust rules | |
| +------------------------------------------------------------+ |
| |
| Issue 2: WAF not blocking expected traffic |
| +------------------------------------------------------------+ |
| | Cause: Rule order or default action misconfigured | |
| | Solution: Check rule priority and default action | |
| +------------------------------------------------------------+ |
| |
| Issue 3: High latency after WAF deployment |
| +------------------------------------------------------------+ |
| | Cause: Too many rules or complex regex patterns | |
| | Solution: Optimize rules, use simpler patterns | |
| +------------------------------------------------------------+ |
| |
| Issue 4: Shield Advanced not protecting resources |
| +------------------------------------------------------------+ |
| | Cause: Resources not enrolled in protection | |
| | Solution: Create protection for each resource | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

Network security is the first line of defense for web applications. SREs configure WAF rules to block attacks, manage Shield Advanced for DDoS protection, use Firewall Manager for org-wide policies, and set up automated incident response. Understanding Layer 3/4 vs Layer 7 protection is critical for designing secure architectures.


Terminal window
# Install tools
sudo pacman -S aws-cli-v2 jq
# === WAF Security Dashboard ===
#!/bin/bash
# ~/bin/waf-status.sh
echo "=== Web ACLs ==="
aws wafv2 list-web-acls --scope REGIONAL \
--query 'WebACLs[*].{Name:Name,Id:Id}' --output table
echo ""
echo "=== IP Sets ==="
aws wafv2 list-ip-sets --scope REGIONAL \
--query 'IPSets[*].{Name:Name,Id:Id}' --output table
echo ""
echo "=== Shield Protections ==="
aws shield list-protections \
--query 'Protections[*].{Name:Name,Resource:ResourceArn}' \
--output table 2>/dev/null || echo "Shield Advanced not enabled"
# === Block IP address immediately (incident response) ===
#!/bin/bash
# ~/bin/waf-block-ip.sh <ip_address>
IP="$1"
IP_SET_ID="your-block-list-id"
IP_SET_NAME="BlockedIPs"
# Get current lock token
LOCK_TOKEN=$(aws wafv2 get-ip-set --scope REGIONAL \
--name "$IP_SET_NAME" --id "$IP_SET_ID" \
--query 'LockToken' --output text)
# Get current addresses and add new one
ADDRESSES=$(aws wafv2 get-ip-set --scope REGIONAL \
--name "$IP_SET_NAME" --id "$IP_SET_ID" \
--query 'IPSet.Addresses' --output json)
NEW_ADDRESSES=$(echo "$ADDRESSES" | jq ". + [\"${IP}/32\"]")
aws wafv2 update-ip-set --scope REGIONAL \
--name "$IP_SET_NAME" --id "$IP_SET_ID" \
--lock-token "$LOCK_TOKEN" \
--addresses "$NEW_ADDRESSES"
echo "Blocked IP: $IP"
# === Check WAF logs for attack patterns ===
aws wafv2 get-sampled-requests \
--web-acl-arn "arn:aws:wafv2:..." \
--rule-metric-name "ALL" \
--scope REGIONAL \
--time-window StartTime=2026-03-01T00:00:00Z,EndTime=2026-03-10T00:00:00Z \
--max-items 100

Anti-Pattern Best Practice
─────────────────────────────────────────────────────────────
❌ Deploying WAF rules in BLOCK ✅ Always start in COUNT mode,
mode without testing analyze logs, then switch
❌ Only using managed rules ✅ Combine managed rules with
custom rules for your app
❌ No rate limiting ✅ Add rate-based rules for
login, API endpoints
❌ Shield Advanced without ✅ Configure health checks and
health checks proactive DRT engagement
❌ WAF on ALB but not CloudFront ✅ WAF on CloudFront edge for
earliest possible blocking

  1. Q: A client is experiencing a DDoS attack — walk me through your response.

    • A: Immediate: (1) Verify with CloudWatch metrics (NetworkIn spike, 5xx errors), (2) If Shield Advanced — contact AWS DRT via Support case, (3) Check WAF logs for attack pattern (geographic, IP range, user-agent), (4) Add rate-based rule to throttle attackers, (5) Block attacking IPs/geos via WAF IP set, (6) If volumetric — Shield Advanced auto-mitigates at Layer 3/4. Post-incident: review with DRT, implement proactive engagement, add CloudFront for edge absorption, enable Shield Advanced cost protection for scaling costs.
  2. Q: How do you prevent false positives with AWS WAF?

    • A: (1) Deploy all new rules in COUNT mode first, (2) Send WAF logs to S3/CloudWatch, (3) Analyze blocked legitimate requests for 1-2 weeks, (4) Create exceptions (label-based or scope-down statements) for false positives, (5) Gradually switch rules to BLOCK mode, (6) Use CAPTCHA action instead of BLOCK for suspicious-but-uncertain traffic. For managed rule groups: use the excludedRules feature to override specific rules causing false positives while keeping the rest active.

Exam Tip

Key Exam Points
+------------------------------------------------------------------+
| |
| 1. WAF operates at Layer 7 (Application layer) |
| |
| 2. Shield Standard is FREE and automatically enabled |
| |
| 3. Shield Advanced costs $3,000/month + includes DRT support |
| |
| 4. WAF can be attached to CloudFront, ALB, and API Gateway |
| |
| 5. Managed rule groups provide pre-configured protection |
| |
| 6. Rate-based rules limit requests per IP address |
| |
| 7. Firewall Manager centralizes security policy management |
| |
| 8. Network Firewall provides VPC-level protection |
| |
| 9. WAF default action determines behavior when no rules match |
| |
| 10. Use COUNT mode to test rules before blocking |
| |
+------------------------------------------------------------------+

Chapter 28 Summary
+------------------------------------------------------------------+
| |
| AWS WAF |
| +------------------------------------------------------------+ |
| | - Web Application Firewall for Layer 7 protection | |
| | - Managed and custom rules | |
| | - IP sets, regex patterns, rate limiting | |
| | - Actions: Allow, Block, Count, Captcha | |
| +------------------------------------------------------------+ |
| |
| AWS Shield |
| +------------------------------------------------------------+ |
| | - Standard: Free, Layer 3/4, auto-enabled | |
| | - Advanced: $3,000/mo, Layer 3/4/7, DRT support | |
| | - DDoS protection for all AWS services | |
| +------------------------------------------------------------+ |
| |
| AWS Firewall Manager |
| +------------------------------------------------------------+ |
| | - Centralized security policy management | |
| | - Works with WAF, Shield, Security Groups | |
| | - Organization-wide deployment | |
| +------------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

Previous Chapter: Chapter 27: AWS KMS, Secrets Manager & Parameter Store Next Chapter: Chapter 29: AWS Security Hub & Detective

Last Updated: March 2026