Attach AWS WAF in the right place and close the bypass
On this page
- Situation and definition
- Simple: a guard at the door
- Developer: a Web ACL attached to a resource
- Architect: the L7 layer in defense in depth
- Picture it as
- Real life: a guard at the building door
- AWS: a Web ACL attached to an ALB
- Mechanism: a request through an ALB with WAF
- Integration map: what can and cannot attach
- Elastic Load Balancing: only the ALB supports WAF
- What about large bodies?
- Is there a proxy in front?
- What if WAF fails?
- Six real-world cases: in front, behind, and the gaps
- Case A · A SQLi request is blocked right at the ALB
- Case B · WAF on CloudFront, but the ALB is still public
- Case C · Static NLB IPs and WAF as well
- Case D · Trying to attach a Web ACL straight to an NLB
- Case E · The payload sits past the first 8 KB of the body
- Case F · API Gateway HTTP API: put CloudFront with WAF in front
- In front, behind: architecture patterns
- When to use WAF and when not to
- Use WAF
- Use another service
- Common myths
- Config examples
- AWS CLI · Attach a Web ACL to an ALB
- EKS Ingress · Attach WAF through an annotation
- JSON · Rate limit /login by forwarded IP
- Self check
- Question 1: static IPs and SQLi
- Question 2: the bypass into the ALB
- Question 3: protecting an HTTP API
- Question 4: body over the limit
- Question 5: UDP flood
- Core terms
- Closing and golden rules
AWS WAF only protects requests that pass through a resource with a Web ACL attached. Picking the right attachment point and closing direct access to the origin are two jobs you have to do together.
| Component | Role |
|---|---|
| Web ACL | A set of rules with priorities and a default action; the unit you attach to a resource |
| Rules and rule groups | Conditions that inspect IP, URI, body, SQLi, XSS and request rate |
| Action | Allow, Block, Count, CAPTCHA or Challenge |
| Attachment point | A resource AWS WAF supports, not an arbitrary instance or pod |
Situation and definition
AWS WAF is a web application firewall: it inspects every HTTP(S) request entering a supported AWS resource, then allows, blocks, counts or challenges it according to the rules you define.
Situation: an online shop runs on EKS behind an ALB, has a mobile API on API Gateway and static files on S3. The security team asks to "turn on WAF for everything". The real question is where WAF can attach, and where the architecture has to change. (Illustrative scenario.)
Goal of this post: afterwards you can place WAF in any architecture yourself, point out which paths still get through, and choose a substitute service when WAF cannot attach. Prerequisites: the parts of an HTTP request, and what a load balancer is.
Simple: a guard at the door
Every building has its own door. A guard stands at the door, checks each visitor's papers and decides whether to let them in or turn them away.
Developer: a Web ACL attached to a resource
Create a Web ACL with rules and attach it to an ALB, CloudFront or REST API. The resource calls WAF before handling the request; if WAF blocks it, the client gets a 403.
Architect: the L7 layer in defense in depth
WAF runs at the edge (CloudFront) or regionally (ALB). Combine it with Shield for L3/L4, Network Firewall for the VPC and Firewall Manager across accounts.
Source: AWS WAF: supported resources.
Picture it as
Real life: a guard at the building door
A guard stands at the building door, opens each letter, and checks it against a list of rules.
AWS: a Web ACL attached to an ALB
Building = resource (ALB, CloudFront). Guard = Web ACL. Rules = rules. Opening the letter = TLS decryption.
Mechanism: a request through an ALB with WAF
Predict before you look: does WAF run before or after the ALB's authenticate step (Cognito/OIDC)?
Before. WAF inspects the request right after the ALB decrypts TLS, before listener rules and authenticate actions.
Request allowed
Client HTTPS
ALB: decrypt TLS
Web ACL: Allow
Listener rules / auth
Target
The response goes back to the client; WAF does not inspect the response.
- Step 1 The ALB terminates TLS. From here on, headers, URI, query, cookies and body are readable. This is why only the ALB (layer 7) can have WAF attached.
- Step 2 WAF evaluates rules by priority, lowest number first. The first matching rule with an Allow or Block action stops evaluation. Count only records the match and moves on. If no rule matches, the default action applies.
- Step 3 Only after WAF lets the request through does the ALB run listener rules (path/host, redirect, authenticate-cognito/oidc). A bot blocked in step 2 never reaches authentication.
- Step 4 The target receives the request with X-Forwarded-For carrying the client IP. WAF can add custom headers prefixed
x-amzn-waf-when the action is configured for it. Labels are used by later rules and appear in logs; a label does not turn into a header sent to the app on its own. - Step 5 WAF only inspects the request; it does not read the response body. Logs (CloudWatch Logs, S3, Firehose) record which rule matched and the final action.
The diagram is a model of the processing order, not a description of AWS internal infrastructure. The frame highlighted in the primary colour marks the resource that has the Web ACL; WAF is not a standalone network proxy.
Source: Rule priority, Labels in WAF.
Integration map: what can and cannot attach
WAF is not a network hop of its own. It can only attach to the resources in the table below. "WAF in front of service X" really means: X sits behind a resource that has WAF attached.
| Resource that can attach | Scope | Body inspected | Notes |
|---|---|---|---|
| CloudFront distribution | Global (us-east-1) | 16 KB, up to 64 KB | Blocks at the edge, before the region |
| Application Load Balancer | Regional | 8 KB fixed | Internal ALBs too. Not supported for ALBs in a Local Zone or on Outposts |
| API Gateway REST API | Regional | 16 KB, up to 64 KB | Attached per stage. HTTP APIs and WebSocket APIs cannot attach |
| AppSync GraphQL API | Regional | 8 KB fixed | Large GraphQL queries easily exceed 8 KB |
| Cognito user pool | Regional | 16 KB, up to 64 KB | Protects sign-in, sign-up and the hosted UI |
| App Runner, Verified Access, Bedrock AgentCore Gateway | Regional | 16 KB, up to 64 KB | Check availability per region |
| Amplify Hosting | Global | 8 KB per the Amplify docs | Check Amplify's integration requirements |
| Cannot attach directly | Why | Use instead |
|---|---|---|
| NLB | Layer 4, does not read HTTP | NLB → ALB+WAF (case C); Network Firewall; Shield Advanced; security groups for the NLB |
| GWLB | Layer 3, for inserting appliances | Third-party appliance (NGFW/IPS) behind the GWLB |
| Classic Load Balancer | Previous generation | Migrate to ALB |
| HTTP API, WebSocket API | Not on the supported list | CloudFront+WAF in front (case F) or a REST API |
| Lambda URL, S3 | Not on the supported list | CloudFront+WAF with OAC in front |
| EC2/ECS/EKS directly | WAF does not attach to instances or pods | ALB (Ingress) or CloudFront VPC Origins |
More cases that are not HTTP or not ingress
| Need | Why WAF cannot do it | Suitable service |
|---|---|---|
| TCP/UDP: games, MQTT, SMTP, databases, SSH | There is no HTTP request to inspect | Network Firewall, Shield, SG/NACL, GWLB+appliance |
| High-volume L3/L4 DDoS | WAF filters L7; it does not absorb floods | Shield Standard (default), Shield Advanced |
| Blocking egress, malicious domains | WAF only looks at incoming requests | Network Firewall, Route 53 Resolver DNS Firewall |
| Internal service-to-service traffic | Only works if traffic goes through an internal ALB | Internal ALB+WAF; SG; VPC Lattice auth policy |
| Inspecting responses, preventing data leaks | WAF does not read the response body | Logic in the app or a DLP solution |
| Managing WAF across many accounts | Doing it by hand misses things | AWS Firewall Manager |
Source: Supported resources, Body inspection limit, WAF for Amplify Hosting.
Elastic Load Balancing: only the ALB supports WAF
| LB type | Layer | WAF | If you still need L7 filtering |
|---|---|---|---|
| Application LB | 7 (HTTP/HTTPS, gRPC) | Yes | Attach the Web ACL directly |
| Network LB | 4 (TCP/UDP/TLS) | No | Put an ALB as the NLB's target |
| Gateway LB | 3 (GENEVE) | No | Third-party appliance behind it |
| Classic LB | 4/7 (legacy) | No | Move to ALB |
What about large bodies?
The ALB sends only the first 8 KB to WAF, and that cannot be raised. Choose oversize handling: Continue, Match or No match (case E).
Is there a proxy in front?
Behind a proxy, the source IP may be the proxy's IP. If you need the user's IP, choose a forwarded-IP configuration and decide which header you trust; do not assume the first IP in X-Forwarded-For is trustworthy.
What if WAF fails?
The waf.fail_open.enabled attribute defaults to false: the ALB does not forward requests when it cannot reach WAF.
-
Each ALB has at most 1 Web ACL. One Web ACL can be attached to many ALBs in the same region.
-
gRPC: body-inspection rules do not apply to gRPC requests. The other rules (headers, IP, URI) still run.
-
HTTP/2 to targets: the target group attribute "WAF HTTP/2 traffic inspection behavior" lets you inspect immediately (the default, suited to bidirectional streaming) or inspect after enough data has arrived to inspect. This setting does not raise the body limit.
-
EKS: the AWS Load Balancer Controller attaches WAF through the
alb.ingress.kubernetes.io/wafv2-acl-arnannotation. When the AWS Load Balancer Controller provisions an NLB, a Service oftype: LoadBalancercreates no WAF attachment point. The LB type also depends on the controller and cluster configuration. -
WebSocket: WAF only inspects the initial upgrade request, not the frames sent afterwards.
Source: ALB attributes, Body and HTTP/2 inspection, Ingress annotations.
Six real-world cases: in front, behind, and the gaps
| Case | Architecture | Branch point | Result |
|---|---|---|---|
| A · SQLi to the ALB | Client → ALB[WAF] → EC2 | SQLi rule matches | 403, target never touched |
| B · Bypassing CloudFront | CF[WAF] → public ALB | Calling the ALB's DNS directly | Gets through; lock the origin |
| C · NLB → ALB | NLB → ALB[WAF] → pod | ALB as the NLB's target | Static IP and WAF together |
| D · WAF on an NLB | NLB passthrough → pod | Association is rejected | No L7 layer |
| E · 20 KB body | ALB[WAF], oversize Continue | Sees only the first 8 KB | May get through; use Match + Block |
| F · HTTP API | CF[WAF] → HTTP API → Lambda | CloudFront stands in | WAF in place; origin checks a header |
Pair 1 · WAF on the ALB blocks correctly, and a bypass makes WAF useless
Case A · A SQLi request is blocked right at the ALB
The Web ACL on the ALB has the managed rule group AWSManagedRulesSQLiRuleSet in Block mode. An attacker sends GET /items?id=1' OR '1'='1. (Illustrative scenario.)
Predict before you run it: does the EC2 target receive this request?
No. WAF matches the SQLi rule during inspection, the ALB returns 403 and does not forward the request to the target group.
SQLi blocked
Client SQLi
ALB + Web ACL
Block: HTTP 403
The target receives nothing when the SQLi rule matches and the action is Block.
- Step 1 The request crosses the internet to the ALB like any other. The ALB decrypts it so it can pass the content to WAF.
- Step 2 The SQLi rule inspects the query string (after text transformations such as URL decode) and matches a SQL injection pattern.
- Step 3 Block is a terminating action: rules with a higher priority number do not run.
- Step 4 The target spends no CPU on this request. The WAF log records terminatingRuleId so you can look it up later. You can replace the 403 with a custom response.
Lesson: when a rule matches with Block, the request stops at the ALB. The app behind it never sees that request.
Case B · WAF on CloudFront, but the ALB is still public
WAF is attached to CloudFront; the ALB behind it has no WAF and its security group allows 0.0.0.0/0. The attacker finds the ALB's DNS name (from logs, historical DNS, TLS certificates). (Illustrative scenario.)
Predict before you run it: can the attacker avoid WAF?
Yes. WAF sits on CloudFront, so a request sent straight to the ALB never passes through that Web ACL.
Main path
Client
CloudFront + WAF
ALB
App
The request passes through the Web ACL at the edge.
Bypass
Attacker
Public ALB DNS
App
It does not go through CloudFront: the edge Web ACL never inspects this request.
- Step 1 The main path works: a malicious request through the CloudFront domain is blocked by the global Web ACL.
- Step 2 This is the branch point. The ALB has public DNS and a security group open to every IP, so the request goes straight in without passing CloudFront.
- Step 3 The ALB has no Web ACL, so nothing inspects the request. Every rule written on CloudFront has no effect on this path.
- Step 4 The fix: allow only the com.amazonaws.global.cloudfront.origin-facing prefix list in the ALB's security group. Add a secret header sent by CloudFront and a listener rule that forwards only when the header is present. Or use CloudFront VPC Origins with an internal ALB.
Lesson: WAF only protects the path through the resource it is attached to. To block everything, you have to close the other paths.
Pair 2 · You need an NLB: the right way and the wrong way
Source: Restrict access to an ALB origin.
Case C · Static NLB IPs and WAF as well
A partner requires a fixed IP allowlist, so you must use an NLB with Elastic IPs. The security team requires WAF. The solution: the NLB's target group has target type alb. (Illustrative scenario.)
Predict before you run it: where in this chain does WAF attach?
On the ALB. The NLB only forwards TCP; the ALB behind it decodes HTTP, so WAF can inspect it.
Keep static IPs, add an L7 layer
Partner
NLB: TCP
ALB + WAF
Pod
The Web ACL is attached to the ALB, not the NLB.
- Step 1 The NLB works at layer 4: it keeps static IPs and forwards TCP connections. It does not read HTTP content.
- Step 2 The NLB's target group registers an ALB directly. The ALB terminates TLS here.
- Step 3 From here the chain is the same as in the mechanism section: WAF evaluates rules by priority on the decrypted request.
- Step 4 The result: the NLB's static IPs and WAF's L7 filtering. The trade-off is paying for two load balancers and an extra network hop.
Lesson: to have both an NLB and WAF, put an ALB with WAF behind the NLB.
Source: ALB as an NLB target.
Case D · Trying to attach a Web ACL straight to an NLB
An EKS Service uses type: LoadBalancer and gets an NLB with TLS passthrough. The engineer tries associate-web-acl with the NLB's ARN. (Illustrative scenario.)
Predict before you run it: is a SQLi payload sent through the NLB blocked?
No. A Web ACL cannot attach to an NLB, and the NLB does not read HTTP, so the payload goes straight to the app.
No WAF on the path
Attacker
NLB: TLS passthrough
Pod
Associating a Web ACL with an NLB is not supported. You need an ALB for HTTP filtering.
- Step 1 With TLS passthrough, the NLB only sees encrypted bytes. There are no headers or URIs to inspect.
- Step 2 The NLB is not on the list of resources WAF supports. The associate-web-acl call fails, so no L7 layer is added.
- Step 3 The pod decrypts and processes the payload. The only protection left is the app's own code.
- Step 4 If you need HTTP filtering: switch to an Ingress ALB, or NLB → ALB as in case C. If you only need L3/L4 protection: use security groups for the NLB, Shield Advanced, AWS Network Firewall.
Lesson: NLB, GWLB and Classic LB cannot have WAF attached. You have to change the architecture; there is no setting to turn on.
Pair 3 · The ALB body limit, and substitutes when WAF cannot attach
Case E · The payload sits past the first 8 KB of the body
An API uploads 20 KB of JSON through an ALB. XSS/SQLi rules inspect the body with oversize handling set to Continue. The malicious payload sits at byte 12,000. (Illustrative scenario.)
Predict before you run it: does WAF see the payload at byte 12,000?
No. With an ALB, WAF only receives the first 8 KB (8,192 bytes). The limit is fixed and cannot be raised.
Body over the limit
20 KB body
ALB + WAF: 8 KB
App: full body
With Continue and no other rule blocking, a payload outside the inspected part can reach the app.
- Step 1 Large bodies are normal for upload APIs or GraphQL. The malicious part is placed at the end of the body.
- Step 2 The body inspection limit for ALB and AppSync is fixed at 8 KB. CloudFront, API Gateway, Cognito, App Runner and Verified Access default to 16 KB and can go up to 64 KB.
- Step 3 Oversize handling = Continue means only the visible part is inspected. The part past the limit is not inspected by this rule. If no other rule blocks, the whole request still reaches the app.
- Step 4 Set
Matchin a rule whose action isBlockto block bodies over the limit;Matchon its own is not a blocking action. Or add a size constraint that blocks bodies over 8 KB on paths that need no upload. For deeper inspection, put CloudFront (up to 64 KB) in front, and still validate in the app.
Lesson: on an ALB, WAF only sees the first 8 KB of the body. For the rest, you choose Match combined with a Block action, or Continue to inspect only the visible part.
Source: Oversize handling and actions.
Case F · API Gateway HTTP API: put CloudFront with WAF in front
The backend uses an API Gateway HTTP API (not a REST API) with Lambda. An HTTP API cannot have a Web ACL attached, so you put CloudFront with WAF in front. (Illustrative scenario.)
Predict before you run it: which region must the CloudFront Web ACL be created in?
us-east-1, with scope CLOUDFRONT, even if the HTTP API lives in another region.
Blocked at the edge
Client
CloudFront + WAF
HTTP API: authorizer
Lambda
The origin must actively check a secret header; CloudFront does not lock the API endpoint by itself.
- Step 1 The API's DNS points to CloudFront, not to the execute-api endpoint.
- Step 2 A CLOUDFRONT-scope Web ACL (created in us-east-1) runs at the edge. Bad requests are blocked before they reach the region.
- Step 3 CloudFront adds a custom origin header. The execute-api endpoint is still public, so this header is how you recognise a request that came through CloudFront.
- Step 4 Configure a Lambda authorizer or backend logic that checks the secret header and rejects requests where it is missing or wrong. Adding the header in CloudFront alone does not stop direct calls to execute-api. Do not write the secret value to logs; rotate it when needed. Alternatively, move to a REST API to attach WAF directly.
Lesson: if a resource cannot have WAF attached, put CloudFront with WAF in front, then close direct access to the origin.
Source: HTTP API Lambda authorizers.
In front, behind: architecture patterns
| Pattern | Chain | Use when | Remember |
|---|---|---|---|
| Single ALB | Internet → ALB[WAF] → app | Simple regional app | 8 KB body |
| Edge + ALB | CloudFront[WAF] → ALB → app | Public app, users in many places | Lock the ALB to traffic from CloudFront only (case B). You can add WAF on the ALB too |
| NLB + ALB | NLB → ALB[WAF] → app | Static IPs, PrivateLink | Costs 2 load balancers (case C) |
| Global Accelerator | GA → ALB[WAF] → app | Anycast IPs, cross-region failover | GA cannot have WAF attached |
| Origin without WAF support | CloudFront[WAF] → S3/Lambda URL/HTTP API | Static sites, serverless | OAC or a secret header (case F) |
When to use WAF and when not to
Use WAF
- OWASP-style flaws: SQLi, XSS, path traversal, Log4j (managed rules).
- Brute force, spam: rate-based rules for /login, /otp.
- Bots, scraping, credential stuffing: Bot Control, ATP, ACFP, CAPTCHA, Challenge.
- Geo, IP reputation: block countries, bad IPs, VPN/Tor.
- Virtual patching: temporarily block a CVE while waiting for a code fix.
Use another service
- TCP/UDP traffic: Network Firewall, Shield, security groups.
- L3/L4 DDoS: Shield Advanced.
- Egress filtering: Network Firewall, DNS Firewall.
- Authentication, authorization: Cognito, IAM, logic in the app.
- Large bodies on an ALB: validate in the app or use CloudFront's 64 KB.
Common myths
| Myth | Reality |
|---|---|
| Turning on WAF for the NLB is enough | An NLB cannot have a Web ACL attached; put an ALB behind it if you need HTTP filtering |
| WAF on CloudFront means the origin is safe | You must close direct access to the origin |
| WAF reads the whole body | ALB/AppSync are limited to 8 KB; supported resources can raise the limit to at most 64 KB |
| WAF stops every DDoS | L3/L4 floods need a suitable layer such as Shield |
| X-Forwarded-For is always the real IP | You must define the trusted proxy chain and how the header is built |
Config examples
AWS CLI · Attach a Web ACL to an ALB
The ARNs are examples. A Web ACL for an ALB uses REGIONAL scope, in the same region as the ALB. Not tested.
aws wafv2 associate-web-acl \
--web-acl-arn arn:aws:wafv2:ap-southeast-1:111122223333:regional/webacl/shop-acl/abcd1234 \
--resource-arn arn:aws:elasticloadbalancing:ap-southeast-1:111122223333:loadbalancer/app/shop-alb/50dc6c495c0c9188
# Keep fail-closed (the default): if WAF does not respond, the ALB does not forward the request
aws elbv2 modify-load-balancer-attributes \
--load-balancer-arn arn:aws:elasticloadbalancing:ap-southeast-1:111122223333:loadbalancer/app/shop-alb/50dc6c495c0c9188 \
--attributes Key=waf.fail_open.enabled,Value=falseEKS Ingress · Attach WAF through an annotation
The AWS Load Balancer Controller creates the ALB and attaches the Web ACL. Values are examples.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: shop
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:ap-southeast-1:111122223333:regional/webacl/shop-acl/abcd1234
spec:
ingressClassName: alb
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: shop
port:
number: 80JSON · Rate limit /login by forwarded IP
A rule for a Web ACL on an ALB behind CloudFront. The threshold is an example; check the schema in the WAF docs before using it.
{
"Name": "login-rate", "Priority": 1,
"Action": { "Block": {} },
"Statement": { "RateBasedStatement": {
"Limit": 100, "EvaluationWindowSec": 300,
"AggregateKeyType": "FORWARDED_IP",
"ForwardedIPConfig": { "HeaderName": "X-Forwarded-For", "FallbackBehavior": "MATCH" },
"ScopeDownStatement": { "ByteMatchStatement": {
"SearchString": "/login", "PositionalConstraint": "STARTS_WITH",
"FieldToMatch": { "UriPath": {} },
"TextTransformations": [{ "Priority": 0, "Type": "NONE" }] } } } },
"VisibilityConfig": { "SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true, "MetricName": "login-rate" }
}Self check
Recall: name the resources that can have WAF attached, and three load balancer types that cannot.
Can attach: CloudFront, ALB, API Gateway REST API, AppSync GraphQL, Cognito user pool, App Runner, Verified Access, Amplify, Bedrock AgentCore Gateway. Cannot attach: NLB, GWLB, Classic LB. To get WAF, put an ALB or CloudFront in the right place in the chain.
Question 1: static IPs and SQLi
A partner only allowlists static IPs, so the system uses an NLB with Elastic IPs. The security team requires blocking SQLi with managed rules. What do you do?
- Attach the Web ACL directly to the NLB.
- Register an ALB as the NLB's target and attach WAF to the ALB.
- Add a security group to the NLB that blocks port 443.
- Turn on Shield Advanced for the Elastic IPs.
Answer yourself before reading the explanation
- WAF on the NLB — Not quite. The NLB is not on the supported resource list, and it does not read HTTP.
- NLB → ALB[WAF] — Correct. The NLB keeps the static IPs, and the ALB decodes HTTP so WAF can run managed rules (case C).
- Security group — Not quite. Security groups filter by IP and port and cannot recognise SQLi. Blocking 443 also breaks the service.
- Shield only — Not quite. Shield protects against DDoS; it does not run layer 7 SQLi rules for the NLB.
Question 2: the bypass into the ALB
The Web ACL on CloudFront blocks well. But app logs show malicious requests whose Host is the ALB's DNS name (*.elb.amazonaws.com). Where do you fix it?
- Add another SQLi rule to the CloudFront Web ACL.
- Lock the ALB: a security group that allows only CloudFront's prefix list, a secret header, or VPC Origins.
- Raise CloudFront body inspection to 64 KB.
- Turn on waf.fail_open.enabled on the ALB.
Answer yourself before reading the explanation
- Add a CF rule — Not quite. These requests do not pass through CloudFront, so rules there never run.
- Lock the origin — Correct. This is the bypass from case B. Once direct calls are blocked, every request has to pass through WAF.
- Raise the body limit — Not quite. Unrelated. The requests do not pass through CloudFront.
- Fail open — Not quite. The ALB has no WAF; fail open would only loosen things further when WAF fails.
Question 3: protecting an HTTP API
A new backend uses an API Gateway HTTP API to keep costs low. It needs rate limiting and bot blocking. Which approach is right?
- associate-web-acl directly with the HTTP API stage.
- Attach WAF to the Lambda function behind it.
- Put CloudFront with WAF in front and check a secret header at the origin; or move to a REST API.
- Use Network Firewall with WAF's managed SQLi rule.
Answer yourself before reading the explanation
- Attach directly — Not quite. Only REST APIs are supported; an HTTP API cannot have a Web ACL attached.
- WAF on Lambda — Not quite. Lambda is not a resource WAF can attach to.
- CloudFront in front — Correct. CloudFront is a WAF-supported resource and stands in for the HTTP API (case F).
- Network Firewall — Not quite. Network Firewall does not use WAF managed rule groups, and has no Bot Control or CAPTCHA.
Question 4: body over the limit
An API uploads 30 KB of JSON through an ALB. A pentest puts a payload at the end of the body and it gets past WAF. What is the best first step?
- Raise the ALB body inspection limit to 64 KB.
- Change the body rule's oversize handling to Match (or block large bodies on paths that don't need them), and validate in the app.
- Add a rate-based rule.
- Switch to an NLB.
Answer yourself before reading the explanation
- Raise the ALB limit — Not quite. On an ALB the limit is fixed at 8 KB; there is no option to raise it.
- Match + validate — Correct. With a Block action, oversize Match treats a body over 8 KB as a match and blocks the request (case E). If a path needs large bodies, put CloudFront's 64 KB in front and validate in the app.
- Rate-based — Not quite. A rate limit counts requests; it does not let WAF read the truncated part of the body.
- Switch to NLB — Not quite. An NLB has no WAF, so you lose the L7 layer entirely.
Question 5: UDP flood
A multiplayer game server uses UDP through an NLB and is being flooded. Which service fits?
- AWS WAF with a rate-based rule.
- Shield Advanced (protecting the Elastic IPs/NLB) combined with network filtering.
- CloudFront in front of the NLB.
- A Cognito user pool.
Answer yourself before reading the explanation
- WAF — Not quite. UDP is not HTTP, and WAF cannot attach to an NLB.
- Shield Advanced — Correct. L3/L4 floods are Shield's job. You can add Network Firewall, security groups and NACLs.
- CloudFront — Not quite. CloudFront serves HTTP(S)/WebSocket; it does not proxy a game's UDP.
- Cognito — Not quite. Cognito is a user authentication service; it does not filter network traffic.
Transfer exercise: your own architecture (try it before opening)
Brief: a system has (1) a Next.js web app on EKS, exposed with a Service of type: LoadBalancer; (2) a mobile API on an API Gateway HTTP API; (3) product images on a public S3 bucket; (4) an admin portal behind an internal ALB. Place WAF for each part, and point out which paths still get through.
Answer criteria: (1) If the LoadBalancer Service provisions an NLB as in the brief, switch to an Ingress ALB with the wafv2-acl-arn annotation; you can add CloudFront in front and lock the ALB. (2) CloudFront+WAF in front of the HTTP API with a secret header check, or move to a REST API. (3) Drop the public bucket and use CloudFront+OAC+WAF. (4) The internal ALB can still have WAF if needed, combined with a security group that allows only VPN/Verified Access. Paths to check for leaks: the execute-api endpoint, the ALB's DNS name, direct S3 URLs.
Core terms
| Term | Meaning |
|---|---|
| Web ACL (protection pack) | A set of rules with priorities and a default action. The unit attached to a resource. |
| Scope | REGIONAL (ALB, API GW…) or CLOUDFRONT (created in us-east-1). |
| WCU | The unit of a rule's compute cost. Each Web ACL has at most 5,000 WCU; anything above 1,500 costs extra. |
| Managed rule group | A rule set maintained by AWS or a vendor: Core rule set, SQLi, Known bad inputs, IP reputation, Bot Control, ATP, ACFP. |
| Rate-based rule | Counts requests per key (IP, forwarded IP, header…) within a time window and applies the action above a threshold. |
| Label | A tag a rule adds to a request, for later rules or the app to act on. |
| Oversize handling | How the part of a request past the inspection limit is handled: Continue, Match, No match. |
| Firewall Manager | Central management of WAF, Shield and Network Firewall across accounts in Organizations. |
Source: WCU, Rate-based rules.
Closing and golden rules
WAF is not a network hop of its own; it attaches to a resource.
Within ELB, only the ALB can have it attached. NLB, GWLB and Classic LB need an architecture change.
If a request has a path into the app that does not pass a resource with WAF attached, WAF has no effect on that request.
If it is not HTTP, use Shield, Network Firewall and security groups.
Layer 7 only·Attach to the right resource·Close the bypass
Source: AWS WAF Developer Guide — supported resources · Body inspection limits · ALB attributes (waf.fail_open.enabled, Local Zone, Outpost) · ALB as an NLB target. Checked on 2026-10-05.
Related posts
AWS IAM policies: follow the request, find the Deny
Animated AWS IAM walkthroughs explain policy types, permissions boundaries, KMS, cross-account access and why one matching Deny overrides every Allow.
AWS acceleration: pick the right service for the slow leg
Six AWS acceleration services — CloudFront, Global Accelerator, S3TA, VPN, DAX, ENA/EFA — chosen by the slow leg, caching and protocol.
Speeding up EC2 and Lambda boot time
How to shorten Lambda cold starts and EC2 scale-out time with SnapStart, Provisioned Concurrency and warm pools, plus where each one stops working.
