skip to content

How do you put AWS WAF and AWS Shield in front of an Amazon CloudFront distribution, and what does each of them actually protect you from?

level: seniorimportance: should knowfreq 50%

answer

  1. two web ACL scopes, only one fits
  2. Global (CloudFront), managed from N. Virginia
  3. floods versus individual bad requests
  4. count first, block later
  5. rules only see what passes through CloudFront

basics

~20 s

Create an AWS WAF web ACL with CloudFront scope (managed from us-east-1) and associate it with the distribution; it filters application-layer requests at the edge. Shield Standard protects network and transport layer floods automatically; Shield Advanced adds paid response support and cost protection.

solid answer

~50 s

AWS WAF web ACLs come in two scopes. A regional web ACL protects an ALB, API Gateway or AppSync; for CloudFront you must create the web ACL with **CloudFront scope**, which is managed from `us-east-1`, and then reference it on the distribution. Once attached, WAF evaluates every viewer request at the edge before it can travel to your origin: AWS Managed Rules groups such as `AWSManagedRulesCommonRuleSet`, rate-based rules that count requests per client IP over a rolling window, geo match, size constraints, and your own conditions — each rule able to allow, block, or merely count while you tune. **Shield Standard** is different in kind: it is automatic, free, always on, and defends the network and transport layers, which is where volumetric floods live. **Shield Advanced** is a paid subscription that adds richer detection, engagement with the AWS Shield Response Team, DDoS cost protection credits, and WAF fee coverage on protected resources. In short, Shield handles the flood and WAF handles the request.

go deeper

for a junior

Know that AWS WAF filters individual HTTP requests by rules while Shield defends against DDoS floods, and that Shield Standard is on by default at no charge for everyone.

for a middle

Explain the scope distinction — a CloudFront web ACL is created with CloudFront scope from us-east-1, a regional one for ALB or API Gateway — and describe the rule types: managed groups, rate-based, geo match, IP sets.

for a senior

Show the rollout discipline and the failure modes: count mode plus WAF logs before blocking, rules scoped to paths for cost, and the fact that edge filtering is only as good as the lockdown that stops attackers reaching the origin directly.

for a principal

Own the decision framework: what Shield Advanced buys relative to the cost of an outage, how WAF request-based charges scale on a high-volume distribution, and who is accountable for rule changes given that a bad rule is an outage with no deploy in your pipeline.

## Attaching WAF to a distribution AWS WAF is scoped. A web ACL created with regional scope can be associated with an Application Load Balancer, an API Gateway stage, an AppSync API or a Cognito user pool in that Region. A web ACL for CloudFront must be created with **CloudFront scope**, which the console labels *Global (CloudFront)* and which is managed through `us-east-1` — the same anchoring that governs CloudFront's viewer certificates. You then reference the web ACL's ARN in the distribution configuration. A common first-day mistake is building the regional web ACL, finding the distribution refuses it, and concluding the feature is broken. ## What WAF actually inspects WAF is an application-layer filter. It sees the request line, headers, query string, cookies and a bounded portion of the body, and evaluates rules in priority order until one produces a terminating action. The building blocks: - **AWS Managed Rules** — curated groups such as `AWSManagedRulesCommonRuleSet` and `AWSManagedRulesAmazonIpReputationList`, maintained by AWS and versioned. They are the fastest way to a reasonable baseline and the fastest way to break a legitimate upload path if you deploy them straight to block. - **Rate-based rules** — count requests from a client IP over a rolling window and act when the count crosses your threshold. This is the practical answer to credential stuffing and scraper floods that are too small to look like a DDoS. - **Geo match, IP sets, regex and size constraints** — the primitives you combine into your own statements, scoped to particular URI paths so a rule protecting `/login` does not affect `/assets`. - **Custom responses** — a blocked request can return a specific status and body rather than a bare 403. Every rule can be set to **Count** rather than Block. The professional rollout is: deploy in count mode, send WAF logs to CloudWatch Logs, S3 or Firehose, look at what *would* have been blocked over a full traffic cycle including batch jobs and mobile clients, then flip rules to block one at a time. ## What Shield covers Shield Standard applies to every AWS customer at no extra charge and needs no configuration. It defends against the common network and transport layer attacks — SYN floods, reflection and amplification — and CloudFront benefits particularly, because the global edge network absorbs and disperses volumetric traffic instead of funnelling it at one Region. Shield Advanced is a paid subscription with an annual commitment. It adds finer detection tuned to your traffic baseline, health-based detection tied to Route 53 health checks, access to the AWS Shield Response Team during an event, proactive engagement, and **DDoS cost protection** — credits for the scaling and data-transfer charges an attack generates, which is often the real financial exposure. It also covers AWS WAF charges on protected resources. Whether it is worth it is a business question about downtime cost and attack likelihood, not a technical one. ## Why the edge is the right place Filtering at CloudFront blocks a bad request at the edge location nearest the attacker, before it consumes a cross-Region path, an origin connection or an application thread. It also scales with the edge network rather than with your origin fleet. The corollary matters just as much: **WAF at CloudFront only sees traffic that arrives through CloudFront.** If your ALB still has a public DNS name and an open security group, an attacker who discovers it bypasses every rule you wrote. Locking the origin down so it accepts only CloudFront traffic is what makes edge filtering meaningful, and a regional web ACL on the ALB is reasonable defence in depth. ## Cost and evaluation discipline WAF bills per web ACL per month, per rule, and per million inspected requests, and some managed groups carry an additional charge. On a high-volume distribution the request dimension dominates, so rules should be scoped to the paths that need them rather than blanket-applied. This is also why a CloudFront Function that rejects obviously malformed requests can be a genuine cost lever alongside WAF, not a replacement for it.

  • Your team wants to enable a managed rule group on a live distribution today. How do you do it safely?
    Add the group in Count mode, not Block. Enable WAF logging and watch a full traffic cycle — including nightly batch jobs, mobile clients and partner integrations — for rules that would have blocked legitimate requests. Then move rules to Block individually, keeping any noisy rule in count with an override. Rolling a whole managed group straight to block is how you take out an upload endpoint.
  • An attacker keeps reaching your application even though the CloudFront web ACL blocks their signature. What is the likely gap?
    They are not going through CloudFront. The origin — an ALB or a public server — still resolves publicly and accepts traffic from anywhere, so the edge rules never see those requests. Restrict the origin to CloudFront traffic and, as defence in depth, attach a regional web ACL to the ALB as well.
  • When does Shield Advanced justify its price?
    When downtime or attack-driven spend is expensive enough to dominate the subscription: consumer-facing revenue systems, regulated services with availability commitments, or organisations with a history of being targeted. The concrete deliverables are response-team engagement during an event and DDoS cost protection credits. For an internal tool, Shield Standard plus WAF is usually the honest answer.

saying these in an interview costs you the question

  • Creates a regional web ACL and expects CloudFront to accept it
  • Says Shield Standard must be enabled and paid for
  • Thinks WAF stops volumetric network floods on its own
  • Deploys managed rule groups straight to block on live traffic
  • Forgets the origin is still reachable around CloudFront

context