c1.6 Protect the endpoint with AWS WAF and rate limiting
Front AI application endpoints with AWS WAF to block known-bad inputs, throttle abusive traffic, and catch common prompt-injection patterns at the perimeter.
Implementation guidance
How to implement on AWS
Attach AWS WAF with the Core rule set and Known bad inputs managed rules, add rate-based rules, and author custom rules for instruction-override and delimiter-manipulation patterns. Validate request schema and prompt length at API Gateway. Add Shield Advanced for high-value endpoints.
Put a shield in front of the model endpoint
AI inference endpoints are attractive targets: attackers probe them with injection payloads, and abusers hammer them to run up token bills or exhaust capacity. AWS WAF sits in front of your API (via CloudFront, Application Load Balancer, or API Gateway) and inspects every request before it reaches your application and the model. Two layers matter most here:
- Managed rule groups catch common web attacks and known-bad inputs.
- Rate-based rules throttle any single client that sends requests too fast.
Rate-limit abusive callers
A rate-based rule counts requests per aggregation key (client IP by default) over an evaluation window and blocks a key that exceeds your limit until it slows down. This caps runaway token spend and blunts denial-of-wallet attacks:
{
"Name": "RateLimitPerIp",
"Priority": 1,
"Statement": {
"RateBasedStatement": {
"Limit": 300,
"EvaluationWindowSec": 300,
"AggregateKeyType": "IP"
}
},
"Action": { "Block": {} },
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "RateLimitPerIp"
}
}
Here a client IP is blocked once it exceeds 300 requests in any 5-minute window. Tune Limit to just above your legitimate peak per client.
Aggregate on something better than IP when you can
Behind NAT or a proxy many users share one IP, so pure-IP limiting is coarse. WAF can aggregate on custom keys — a forwarded IP, an API key header, or a session identifier — so you throttle the actual abuser instead of everyone behind the same gateway. Pair the rate rule with a scope-down statement so it only counts the requests that hit your inference path (e.g. /v1/generate), not static assets.
Start in count mode
Deploy new rules in Count mode first and watch the CloudWatch metrics; once you confirm they are not catching legitimate traffic, switch the action to Block. This avoids taking your own users offline with a mistuned limit.
Acceptance criteria
WAF is attached to the AI endpoint with rate limiting and managed rules; a synthetic injection pattern is blocked; API Gateway rejects oversized/malformed prompts.
Practical implementation
How this control is implemented in each reference architecture:
WAF and API Gateway sit at the Application account edge, throttling and filtering traffic before it can trigger a cross-account model call.
- Attach AWS WAF to the AI endpoint (CloudFront/ALB/API Gateway) in the Application account with the Core rule set and Known-bad-inputs managed rules.
- Add rate-based rules and custom rules for instruction-override and delimiter-manipulation patterns, and validate request schema and prompt length at API Gateway.
- Add AWS Shield Advanced on high-value public endpoints for managed DDoS protection.
How to validate: WAF is attached with rate limiting and managed rules; a synthetic injection pattern is blocked; API Gateway rejects oversized/malformed prompts before they reach the model.
Avoid: Putting WAF only on a marketing site and leaving the AI API endpoint unprotected. Attach WAF and request validation to the endpoint that actually reaches the model.
WAF and API Gateway protect the application tier's public endpoint so abusive or malformed requests are filtered before the model-invocation role is assumed.
- Attach AWS WAF to the application tier's public endpoint with the Core rule set, Known-bad-inputs rules, and rate-based rules.
- Validate prompt length and request schema at API Gateway and add custom WAF rules for common prompt-injection patterns.
- Add Shield Advanced if the endpoint is a high-value public target.
How to validate: WAF with rate limiting is attached to the AI endpoint; a synthetic injection is blocked; API Gateway rejects oversized prompts.
Avoid: Relying on the guardrail alone for abuse control. WAF and rate limits stop volumetric and malformed traffic cheaply before it ever reaches the model.
Threats addressed
- Automated prompt stuffing and injection attempts at scale.
- Resource exhaustion / denial of service through unthrottled requests.
AWS services
Pricing
AWS WAF bills a monthly charge per web ACL and per rule, plus a charge per million requests inspected. Rate-based rules are included in the standard rule pricing; managed rule groups from AWS or the Marketplace may add a subscription fee. See Rate-based rule statement in AWS WAF.
Framework mappings
OWASP GenAI/LLM Top 10 (2026)
- LLM01 Prompt Injection
- LLM06 Unbounded Consumption
NIST AI Risk Management Framework (AI 100-1)
- MANAGE.1 AI risks are prioritized, responded to and managed
- MANAGE.4 Risk treatments, monitoring and response are documented and applied
AWS Well-Architected Generative AI Lens (Security)
- GENSEC04-BP02 Sanitize and validate user inputs to foundation models
Learning resources
- AWS WAF developer guide (doc)
References
- AWS SRA for AI — Capability 1, Application security layer
AI Security Maturity Model