Enable the WAF's rate‑limit and anomaly‑detection modules, then tune per‑endpoint thresholds to block traffic that exceeds normal baselines.
Steps
1. Profile baseline traffic – Use CloudWatch metrics (AWS), Azure Monitor, or GCP Monitoring for 7‑day average request rate per URI. Example baseline: 120 rps for /api/*.
2. Create a rate‑based rule – Set the limit slightly above baseline (e.g., 200 rps) and define a 5‑minute aggregation window.
3. Add an anomaly‑detection rule – Enable “IP reputation” and “SQLi/XSS” signatures; set the action to block for scores ≥ 5.
4. Scope the rule – Apply to the specific CloudFront distribution, Azure Front Door route, or GCP backend service.
5. Whitelist health‑check sources – Add the load‑balancer IP ranges to an allow‑list rule with priority higher than the rate rule.
6. Enable automatic mitigation – Turn on “auto‑scale protection” (AWS Shield Advanced) or “adaptive protection” (Azure) to raise limits during legitimate spikes.
7. Monitor and adjust – Set CloudWatch alarm on WAFBlockedRequests > 5 % of total; refine thresholds weekly.
Tool comparison
| Provider | Rate‑limit API | Anomaly detection | Auto‑scale flag |
|----------|----------------|-------------------|-----------------|
| AWS WAF | aws wafv2 create-rate-based-rule | Managed rule groups | EnableManagedRuleGroupStatement with AWSManagedRulesAnonymousIpList |
| Azure Front Door WAF | az network front-door waf-policy rule create --type RateLimit | ManagedRuleSet | policySettings.enableAutoTune=true |
| GCP Cloud Armor | gcloud compute security-policies rules create --expression="request.rate < 200" | preconfigured-waf | adaptiveProtectionConfig.enabled=true |
Example CLI snippets
# AWS CLI – rate‑based rule
aws wafv2 create-rate-based-rule \
--name high‑rate‑api \
--scope REGIONAL \
--metric-name HighRateAPI \
--rate-key IP \
--rate-limit 200 \
--visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName=HighRateAPI# Azure CLI – rate limit rule
az network front-door waf-policy rule create \
--policy-name prodWaf \
--resource-group rg-prod \
--name apiRateLimit \
--priority 100 \
--action Block \
--type RateLimit \
--rate-limit-threshold 200 \
--rate-limit-duration 5Gotcha: Aggressive limits can drop legitimate burst traffic from autoscaling pods; always whitelist health‑check IPs and keep a low‑priority “bypass” rule for known CDN edge ranges.