Skip to Content
Cloud Engineering Academy
5. Security for Banking & Finance

AWS WAF and AWS Shield

Protect Harbourline's public banking APIs with AWS WAF managed rules, rate limiting and safe logging, and understand what Shield Standard gives you free and when Shield Advanced is worth USD 3,000 a month.

intermediate⏱ 2 h 🟡 Low costSCS-C03SAA-C03DVA-C03

Assumes: .NET 10 LTS · AWS SDK for .NET v4 · AWS CLI v2 · CDK v2 (Amazon.CDK.Lib 2.277.0) · Terraform AWS provider v6 · Region us-east-1. Verified against official sources on 2026-11-17.

Learning objectives

By the end of this lesson you can:

  • Explain web ACLs (now also called protection packs in the new WAF console), rules, rule groups, rule priority, actions and web ACL capacity units (WCUs).
  • Choose AWS managed rule groups for a banking API, including when the paid Bot Control, Account Takeover Prevention (ATP) and Account Creation Fraud Prevention (ACFP) groups are justified.
  • Write a rate-based rule that protects a login endpoint, with a custom JSON 429 response.
  • Roll out rules safely in Count mode, read the logs, and redact sensitive fields before they are stored.
  • Compare Shield Standard and Shield Advanced, and explain the commitment, the Shield Response Team and cost protection.
  • Deploy and tear down a web ACL on an API Gateway stage with CDK (C#) or Terraform within one session.

Prerequisites

Why this matters in banking

Banks are among the most attacked organisations on the internet. Three attack families matter most for Harbourline's public APIs:

  1. Credential stuffing — attackers replay username/password pairs leaked from other websites against the mobile-banking login. Even a 0.1% success rate on a million attempts is a thousand compromised customers, each a potential fraud case and a regulatory notification.
  2. Application attacks — injection, path traversal, deserialisation exploits and scanners probing for /.env or admin pages.
  3. DDoS — volumetric floods at the network layer, or request floods at the application layer that exhaust your .NET instances and database connections. For a bank, an outage of online payments is an operational resilience event that regulators expect you to plan for and report on.

AWS WAF and AWS Shield do not replace secure code (you still validate input and use parameterised queries), but they stop a large volume of junk before it reaches your code, give you a fast lever during an incident, and produce the logs your SOC needs.

The idea in plain language

AWS WAF is a web application firewall: a filter in front of an HTTP endpoint that looks at each request — IP address, headers, path, query string, body — and decides to allow, block, count, or challenge it (CAPTCHA or a silent browser Challenge). You put rules in a web ACL and attach it to CloudFront, an Application Load Balancer, an API Gateway REST API stage, a Cognito user pool, AppSync, or Verified Access.

AWS Shield is DDoS protection. Shield Standard is on for every AWS customer at no charge and absorbs common network- and transport-layer floods (SYN floods, UDP reflection). Shield Advanced is a paid subscription that adds tailored detection, automatic application-layer mitigation (using WAF), access to the Shield Response Team (SRT), and financial protection against scaling costs caused by an attack.

Analogy: WAF is the security guard at the branch door who checks every visitor against a list of known fraudsters, turns away anyone carrying a crowbar, and stops one person from walking in and out fifty times a minute. Shield Standard is the building's structure that stays up when a crowd pushes against the walls. Shield Advanced is a contract with a specialist crowd-control firm that has a 24/7 phone line and reimburses you for the extra staff you had to hire during the riot.

What problem the AWS services solve

ConceptWhat it isNotes and limits (checked 2026-11-17)
Web ACL / protection packOrdered list of rules plus a default action100 per account per Region by default; a CloudFront web ACL must be created in us-east-1 with scope CLOUDFRONT
RuleA statement (match condition) plus an actionEvaluated in priority order (lowest number first); a terminating action stops evaluation
Rule groupReusable set of rules: your own, AWS managed, or AWS MarketplaceManaged groups are versioned and updated by AWS or the seller
WCUCapacity cost of rulesMax 5,000 WCUs per web ACL; above 1,500 WCUs you pay extra per request
Rate-based ruleCounts requests per aggregation key (IP, header, …) over a windowMinimum limit 10; windows of 60, 120, 300 (default) or 600 seconds; max 10 per web ACL
LabelsTags that rules add to a request so later rules can act on themE.g. block only requests that ATP labelled credential_compromised
LoggingFull request logs to CloudWatch Logs, S3 or FirehoseDestination names must start with aws-waf-logs-; redaction of selected fields supported
Body inspectionHow much of the request body WAF readsALB: fixed 8 KB. API Gateway, CloudFront, Cognito, Verified Access: 16 KB default, up to 64 KB (extra cost)

Limitations to be honest about: WAF only sees HTTP(S) requests to supported AWS resources; it does not protect an EC2 instance with a public IP or an NLB. It cannot understand your business logic (for example "this customer is moving money to a new payee for the first time"). Managed rules can produce false positives on legitimate banking payloads — such as ISO 20022 XML or long JWTs — which is why you start in Count mode.

Shield Standard vs Shield Advanced

Shield StandardShield Advanced
PriceIncluded at no extra costUSD 3,000 per month with a 1-year commitment, plus data-transfer-out usage fees; one fee covers all accounts in an Organizations consolidated-billing family
Layer 3/4 protectionAutomatic for all customersEnhanced, with resource-specific detection baselines
Layer 7 protectionBring your own WAF rulesAutomatic application-layer DDoS mitigation (adds a 150-WCU rule group), plus the Anti-DDoS managed rule group
Protected resourcesAllYou choose: CloudFront, Route 53 hosted zones, Global Accelerator, ALB, Classic Load Balancer, Elastic IPs
WAF chargesNormalStandard WAF fees covered for protected resources (web ACL, rules, requests up to 1,500 WCUs and default body size; up to 50 billion requests per month). Bot Control, Fraud Control, CAPTCHA and WCUs above 1,500 are still charged
Shield Response TeamNoYes — requires a Business or Enterprise Support plan
Cost protectionNoService credits for scaling charges caused by a DDoS attack on protected resources (claim process applies)
Health-based detectionNoUses Route 53 health checks to reduce false positives and speed detection
VisibilityBasicAttack diagnostics, CloudWatch metrics, global threat dashboard

AWS Shield network security director is a separate capability that discovers your network resources, checks security groups, NACLs and WAF configurations against best practices, and raises prioritised findings. It launched in preview in June 2025, gained multi-account analysis in December 2025, and sends findings to AWS Security Hub since March 2026. It is not included in a Shield Advanced subscription. ⚠ VERIFY its current availability status and pricing before you rely on it.

Microsoft / Azure comparison

You know (Microsoft/Azure)AWS equivalentWhat's different
Azure Web Application Firewall on Application Gateway or Front DoorAWS WAF on ALB, API Gateway or CloudFrontOne WAF service attaches to many resource types; rules use WCUs, not SKUs
OWASP CRS managed rule set (DRS)AWSManagedRulesCommonRuleSet + KnownBadInputs + SQLiRuleSetAWS groups are AWS-authored, not literal OWASP CRS
Azure WAF rate-limit custom ruleRate-based ruleWindows of 1–10 minutes, aggregation on IP, forwarded IP, headers, cookies, labels and more
Azure WAF Bot Manager rule setBot Control (Common / Targeted)Targeted level uses browser interrogation and tokens; extra fees
Azure DDoS Network ProtectionShield AdvancedSimilar commercial model (fixed monthly fee, response team, cost protection)
Azure DDoS infrastructure protection (free)Shield StandardAutomatic, free
Azure Firewall Manager WAF policiesAWS Firewall Manager WAF/Shield policiesOrg-wide enforcement, priced per policy per Region
ASP.NET Core rate limiting middleware(complementary)Keep app-level limits per customer; WAF limits per IP or header at the edge

Architecture

Most banks attach a web ACL at the edge (CloudFront) to stop traffic as close to the attacker as possible, and optionally a second, simpler one at the regional layer to protect against requests that bypass CloudFront. In the lab you use only a regional web ACL on an API Gateway stage, because it is cheaper and quicker.

Rule evaluation inside a web ACL

Order matters: cheap, high-confidence rules (reputation lists, rate limits) go first; expensive inspection later. Allow rules for trusted sources go first only if you are sure they cannot be spoofed — never allow-list on a header the client controls.

Step-by-step implementation

Inventory your endpoints and their risk

List every public path and what it does. For the Accounts API: POST /v1/auth/login (credential stuffing target), GET /v1/accounts/{id} (enumeration target), POST /v1/payments (fraud target, requires Idempotency-Key). Note the expected request rates per customer and per IP — mobile carriers put thousands of customers behind one IP, so per-IP limits must be generous.

Start with baseline managed rule groups

Add AWSManagedRulesAmazonIpReputationList (25 WCUs), AWSManagedRulesCommonRuleSet (700 WCUs), AWSManagedRulesKnownBadInputsRuleSet (200 WCUs) and AWSManagedRulesSQLiRuleSet. That is under 1,500 WCUs, so no capacity surcharge. Set the managed groups' override action to Count for the first deployment.

Add a rate-based rule for login

Scope it with a scope-down statement that matches only /v1/auth/login. Use a 5-minute window and a limit agreed with the fraud team. Return a custom 429 with a JSON body in the ProblemDetails (RFC 9457) shape your clients already understand.

Turn on logging with redaction — before production traffic

Send logs to a CloudWatch Logs group named aws-waf-logs-hl-m05-accounts-api with retention set (for example 30 days in the lab; your records policy in production). Redact the authorization header and the query string. WAF logs contain full request metadata; storing bearer tokens or customer identifiers in a log group widely readable by engineers is itself a data-protection incident.

Run in Count mode and tune

Send normal traffic (your integration tests, a synthetic monitor) for a period agreed with the business. Query the logs for rules that matched legitimate requests. Common false positives in banking: SizeRestrictions_BODY on large statement downloads posted as JSON, CrossSiteScripting_BODY on free-text payment references containing <, and NoUserAgent_HEADER on a partner's batch client. Override only the specific rule to Count (rule action override), not the whole group.

Switch to Block and alarm

Change the override action to None (meaning "use the rule group's own actions"). Create CloudWatch alarms on BlockedRequests for each rule's metric so a sudden spike pages the on-call engineer.

Decide on paid protections with a cost model

ATP on the login endpoint charges a subscription plus a per-request fee that is far higher than base WAF — use a scope-down so it only inspects the login path. Bot Control Common is inexpensive; Targeted costs more and needs the WAF client SDK or challenge actions. Shield Advanced is justified when you have a significant revenue or regulatory exposure to DDoS, multiple internet-facing resources, and want SRT support.

Govern centrally

In a multi-account bank, use AWS Firewall Manager from a security tooling account to require a baseline web ACL on every ALB, API Gateway stage and CloudFront distribution, and to auto-remediate drift. Application teams can add their own rules in a second rule group slot.

AWS Console instructions

  1. Console → WAF & Shield. The new console experience calls web ACLs protection packs; the classic view still says Web ACLs. Both refer to the same resource.
  2. Choose Create protection pack (web ACL) → resource type Regional resources → Region US East (N. Virginia) → Add associated resources → pick the API Gateway REST API stage hl-m05-accounts-api / prod.
  3. Add rules → Add managed rule groups → AWS managed rule groups. Enable Amazon IP reputation list, Core rule set, Known bad inputs, SQL database. For each, choose Edit → Override all rule actions to Count for the first rollout.
  4. Add rules → Add my own rules → Rule builder → Rate-based rule. Name login-rate-limit, rate limit 100, evaluation window 5 minutes, aggregate on Source IP address, scope Only consider requests that match URI path starts with /v1/auth/login. Action Block → Enable custom response → code 429 → body key rate-limited.
  5. Set rule priority as in the diagram above. Default action Allow.
  6. After creation: Logging and metrics → Enable logging → CloudWatch Logs log group aws-waf-logs-hl-m05-accounts-api → Redacted fields: Header authorization, Query string.
  7. Shield: WAF & Shield → AWS Shield → Overview shows the subscription state. Do not click Subscribe to Shield Advanced in a learning account: it starts a one-year commitment.

AWS CLI

export AWS_PROFILE=learn-sandbox AWS_REGION=us-east-1

# 1. Show the WCU capacity a set of rules would need before you create the web ACL
aws wafv2 check-capacity --scope REGIONAL --rules file://rules.json

# 2. Create the web ACL (rules.json contains the rules shown in the IaC section)
aws wafv2 create-web-acl --name hl-m05-accounts-api-acl --scope REGIONAL \
  --default-action Allow={} \
  --visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName=hl-m05-accounts-api-acl \
  --custom-response-bodies '{"rate-limited":{"ContentType":"APPLICATION_JSON","Content":"{\"type\":\"https://harbourline.example.com/problems/rate-limited\",\"title\":\"Too many requests\",\"status\":429}"}}' \
  --rules file://rules.json \
  --tags Key=Project,Value=cea-lab Key=Lab,Value=m05-l15 Key=Environment,Value=learn Key=Owner,Value=alex

# 3. Attach it to an API Gateway REST API stage (ARN format for REST API stages)
aws wafv2 associate-web-acl \
  --web-acl-arn arn:aws:wafv2:us-east-1:111122223333:regional/webacl/hl-m05-accounts-api-acl/EXAMPLE-ID \
  --resource-arn arn:aws:apigateway:us-east-1::/restapis/a1b2c3d4e5/stages/prod

# 4. Create the log group (name MUST start with aws-waf-logs-) with retention
aws logs create-log-group --log-group-name aws-waf-logs-hl-m05-accounts-api
aws logs put-retention-policy --log-group-name aws-waf-logs-hl-m05-accounts-api --retention-in-days 30

# 5. Enable logging with redaction of the Authorization header and the query string
aws wafv2 put-logging-configuration --logging-configuration '{
  "ResourceArn": "arn:aws:wafv2:us-east-1:111122223333:regional/webacl/hl-m05-accounts-api-acl/EXAMPLE-ID",
  "LogDestinationConfigs": ["arn:aws:logs:us-east-1:111122223333:log-group:aws-waf-logs-hl-m05-accounts-api"],
  "RedactedFields": [ { "SingleHeader": { "Name": "authorization" } }, { "QueryString": {} } ]
}'

# 6. Look at a sample of recent requests matched by the login rate rule (last 3 hours max)
aws wafv2 get-sampled-requests \
  --web-acl-arn arn:aws:wafv2:us-east-1:111122223333:regional/webacl/hl-m05-accounts-api-acl/EXAMPLE-ID \
  --rule-metric-name login-rate-limit --scope REGIONAL --max-items 50 \
  --time-window StartTime=$(date -u -d '-1 hour' +%s),EndTime=$(date -u +%s)

# 7. Which IPs are currently being rate limited by the rule?
aws wafv2 get-rate-based-statement-managed-keys --scope REGIONAL \
  --web-acl-name hl-m05-accounts-api-acl --web-acl-id EXAMPLE-ID --rule-name login-rate-limit

# 8. Check whether this account has Shield Advanced (read-only — does not subscribe)
aws shield get-subscription-state

Notes on each command:

  1. check-capacity tells you the WCUs before you hit the 5,000 limit or the 1,500 pricing threshold.
  2. --custom-response-bodies defines reusable bodies that rules reference by key. JSON inside JSON needs escaping; in practice keep this in a file.
  3. REST API stages use arn:aws:apigateway:<region>::/restapis/<api-id>/stages/<stage>. HTTP APIs (API Gateway v2) cannot be associated with WAF directly — put CloudFront in front if you use them.
  4. The aws-waf-logs- prefix is mandatory for all three destination types.
  5. The log group ARN must not end in :*. Many tools (including CDK's LogGroupArn) add :*; WAF rejects it.
  6. get-sampled-requests is free and great for quick tuning, but only covers up to the last three hours and a sample.
  7. Lists the aggregation keys (IPs) that are currently over the limit — useful during an incident.
  8. Shows ACTIVE or INACTIVE; it changes nothing.

Infrastructure as Code

infra/ApiWafStack.cs
using Amazon.CDK;
using Amazon.CDK.AWS.Logs;
using Amazon.CDK.AWS.WAFv2;
using Constructs;

namespace Harbourline.Accounts.Infra;

public sealed class ApiWafStackProps : StackProps
{
    /// <summary>ARN of the API Gateway REST API stage to protect.</summary>
    public required string ApiStageArn { get; init; }

    /// <summary>When true, managed groups only Count (first rollout).</summary>
    public bool CountOnly { get; init; } = true;
}

public sealed class ApiWafStack : Stack
{
    public ApiWafStack(Construct scope, string id, ApiWafStackProps props) : base(scope, id, props)
    {
        static CfnWebACL.VisibilityConfigProperty Metrics(string name) => new()
        {
            CloudWatchMetricsEnabled = true,
            SampledRequestsEnabled = true,
            MetricName = name,
        };

        // Managed groups: Count during rollout, then None (= use the group's own Block actions).
        CfnWebACL.OverrideActionProperty Override() => props.CountOnly
            ? new CfnWebACL.OverrideActionProperty { Count = new Dictionary<string, object>() }
            : new CfnWebACL.OverrideActionProperty { None = new Dictionary<string, object>() };

        CfnWebACL.RuleProperty Managed(string name, int priority) => new()
        {
            Name = name,
            Priority = priority,
            OverrideAction = Override(),
            Statement = new CfnWebACL.StatementProperty
            {
                ManagedRuleGroupStatement = new CfnWebACL.ManagedRuleGroupStatementProperty
                {
                    VendorName = "AWS",
                    Name = name,
                },
            },
            VisibilityConfig = Metrics(name),
        };

        var loginRateLimit = new CfnWebACL.RuleProperty
        {
            Name = "login-rate-limit",
            Priority = 1,
            Action = new CfnWebACL.RuleActionProperty
            {
                Block = new CfnWebACL.BlockActionProperty
                {
                    CustomResponse = new CfnWebACL.CustomResponseProperty
                    {
                        ResponseCode = 429,
                        CustomResponseBodyKey = "rate-limited",
                        ResponseHeaders = new[]
                        {
                            new CfnWebACL.CustomHTTPHeaderProperty { Name = "Retry-After", Value = "300" },
                        },
                    },
                },
            },
            Statement = new CfnWebACL.StatementProperty
            {
                RateBasedStatement = new CfnWebACL.RateBasedStatementProperty
                {
                    Limit = 100,                 // requests per window per IP (minimum allowed is 10)
                    EvaluationWindowSec = 300,   // 60, 120, 300 or 600
                    AggregateKeyType = "IP",
                    ScopeDownStatement = new CfnWebACL.StatementProperty
                    {
                        ByteMatchStatement = new CfnWebACL.ByteMatchStatementProperty
                        {
                            FieldToMatch = new CfnWebACL.FieldToMatchProperty { UriPath = new Dictionary<string, object>() },
                            PositionalConstraint = "STARTS_WITH",
                            SearchString = "/v1/auth/login",
                            TextTransformations = new[]
                            {
                                new CfnWebACL.TextTransformationProperty { Priority = 0, Type = "LOWERCASE" },
                            },
                        },
                    },
                },
            },
            VisibilityConfig = Metrics("login-rate-limit"),
        };

        var webAcl = new CfnWebACL(this, "AccountsApiAcl", new CfnWebACLProps
        {
            Name = "hl-m05-accounts-api-acl",
            Scope = "REGIONAL",
            DefaultAction = new CfnWebACL.DefaultActionProperty { Allow = new CfnWebACL.AllowActionProperty() },
            VisibilityConfig = Metrics("hl-m05-accounts-api-acl"),
            CustomResponseBodies = new Dictionary<string, object>
            {
                ["rate-limited"] = new CfnWebACL.CustomResponseBodyProperty
                {
                    ContentType = "APPLICATION_JSON",
                    Content = """{"type":"https://harbourline.example.com/problems/rate-limited","title":"Too many requests","status":429}""",
                },
            },
            Rules = new object[]
            {
                Managed("AWSManagedRulesAmazonIpReputationList", 0),
                loginRateLimit,
                Managed("AWSManagedRulesCommonRuleSet", 2),
                Managed("AWSManagedRulesKnownBadInputsRuleSet", 3),
                Managed("AWSManagedRulesSQLiRuleSet", 4),
            },
        });

        _ = new CfnWebACLAssociation(this, "AccountsApiAclAssociation", new CfnWebACLAssociationProps
        {
            ResourceArn = props.ApiStageArn,
            WebAclArn = webAcl.AttrArn,
        });

        // Log group name must start with aws-waf-logs-; retention is mandatory in Harbourline labs.
        var logGroup = new LogGroup(this, "WafLogs", new LogGroupProps
        {
            LogGroupName = "aws-waf-logs-hl-m05-accounts-api",
            Retention = RetentionDays.ONE_MONTH,
            RemovalPolicy = RemovalPolicy.DESTROY, // ⚠ learning shortcut: RETAIN in production
        });

        _ = new CfnLoggingConfiguration(this, "WafLogging", new CfnLoggingConfigurationProps
        {
            ResourceArn = webAcl.AttrArn,
            // WAF rejects the ":*" suffix that LogGroupArn includes, so build the ARN explicitly.
            LogDestinationConfigs = [FormatArn(new ArnComponents
            {
                Service = "logs",
                Resource = "log-group",
                ResourceName = logGroup.LogGroupName,
                ArnFormat = ArnFormat.COLON_RESOURCE_NAME,
            })],
            RedactedFields = new object[]
            {
                new CfnLoggingConfiguration.FieldToMatchProperty
                {
                    SingleHeader = new Dictionary<string, object> { ["Name"] = "authorization" },
                },
                new CfnLoggingConfiguration.FieldToMatchProperty { QueryString = new Dictionary<string, object>() },
            },
        });

        foreach (var (k, v) in new[] { ("Project", "cea-lab"), ("Lab", "m05-l15"), ("Environment", "learn"), ("Owner", "alex") })
        {
            Amazon.CDK.Tags.Of(this).Add(k, v);
        }
    }
}

Complete code

Tuning WAF is mostly reading logs. This .NET 10 console app reads WAF log records (one JSON object per line, as written to CloudWatch Logs or S3) and produces a tuning report: which rules terminated requests, which rules only counted (candidates for switching to Block, or false positives), and the top client IPs. It runs offline on a sample file, so you can practise without an AWS account; point it at an exported log file later.

WafLogReport/WafLogReport.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <RootNamespace>Harbourline.Security.WafLogReport</RootNamespace>
  </PropertyGroup>
</Project>
WafLogReport/WafLogRecord.cs
using System.Text.Json.Serialization;

namespace Harbourline.Security.WafLogReport;

// Only the fields we need from the AWS WAF log format.
public sealed record WafLogRecord(
    [property: JsonPropertyName("timestamp")] long Timestamp,
    [property: JsonPropertyName("action")] string Action,
    [property: JsonPropertyName("terminatingRuleId")] string TerminatingRuleId,
    [property: JsonPropertyName("httpRequest")] WafHttpRequest HttpRequest,
    [property: JsonPropertyName("ruleGroupList")] List<WafRuleGroup>? RuleGroupList,
    [property: JsonPropertyName("nonTerminatingMatchingRules")] List<WafMatchedRule>? NonTerminatingMatchingRules);

public sealed record WafHttpRequest(
    [property: JsonPropertyName("clientIp")] string ClientIp,
    [property: JsonPropertyName("country")] string Country,
    [property: JsonPropertyName("uri")] string Uri,
    [property: JsonPropertyName("httpMethod")] string HttpMethod);

public sealed record WafRuleGroup(
    [property: JsonPropertyName("ruleGroupId")] string RuleGroupId,
    [property: JsonPropertyName("nonTerminatingMatchingRules")] List<WafMatchedRule>? NonTerminatingMatchingRules);

public sealed record WafMatchedRule(
    [property: JsonPropertyName("ruleId")] string RuleId,
    [property: JsonPropertyName("action")] string Action);
WafLogReport/Program.cs
using System.Text.Json;
using Harbourline.Security.WafLogReport;

var path = args.Length > 0 ? args[0] : "sample-waf-logs.jsonl";
var records = new List<WafLogRecord>();

foreach (var line in File.ReadLines(path))
{
    if (string.IsNullOrWhiteSpace(line)) continue;
    try
    {
        var record = JsonSerializer.Deserialize<WafLogRecord>(line);
        if (record is not null) records.Add(record);
    }
    catch (JsonException ex)
    {
        Console.Error.WriteLine($"Skipping malformed line: {ex.Message}");
    }
}

Console.WriteLine($"Analysed {records.Count} requests from {path}\n");

// 1. Which rule ended evaluation, per action?
Console.WriteLine("Terminating rules:");
foreach (var g in records.GroupBy(r => (r.Action, r.TerminatingRuleId)).OrderByDescending(g => g.Count()))
{
    Console.WriteLine($"  {g.Key.Action,-8} {g.Key.TerminatingRuleId,-45} {g.Count(),6}");
}

// 2. Rules that matched in COUNT mode — inside managed groups or at web ACL level.
var counted = records
    .SelectMany(r => (r.RuleGroupList ?? [])
        .SelectMany(rg => (rg.NonTerminatingMatchingRules ?? []).Select(m => $"{ShortName(rg.RuleGroupId)}:{m.RuleId}"))
        .Concat((r.NonTerminatingMatchingRules ?? []).Select(m => m.RuleId)))
    .GroupBy(x => x)
    .OrderByDescending(g => g.Count());

Console.WriteLine("\nCounted (not blocked) matches — review before switching to Block:");
foreach (var g in counted)
{
    Console.WriteLine($"  {g.Key,-60} {g.Count(),6}");
}

// 3. Top client IPs among blocked requests (IPs are personal data under UK GDPR — keep reports internal).
Console.WriteLine("\nTop blocked client IPs:");
foreach (var g in records.Where(r => r.Action == "BLOCK").GroupBy(r => r.HttpRequest.ClientIp)
             .OrderByDescending(g => g.Count()).Take(5))
{
    Console.WriteLine($"  {g.Key,-16} {g.Count(),6}  e.g. {g.First().HttpRequest.HttpMethod} {g.First().HttpRequest.Uri}");
}

return 0;

static string ShortName(string ruleGroupId) =>
    ruleGroupId.Contains("#", StringComparison.Ordinal) ? ruleGroupId[(ruleGroupId.LastIndexOf('#') + 1)..] : ruleGroupId;
WafLogReport/sample-waf-logs.jsonl
{"timestamp":1795392000000,"action":"BLOCK","terminatingRuleId":"login-rate-limit","httpRequest":{"clientIp":"198.51.100.23","country":"GB","uri":"/v1/auth/login","httpMethod":"POST"},"ruleGroupList":[],"nonTerminatingMatchingRules":[]}
{"timestamp":1795392000500,"action":"BLOCK","terminatingRuleId":"login-rate-limit","httpRequest":{"clientIp":"198.51.100.23","country":"GB","uri":"/v1/auth/login","httpMethod":"POST"},"ruleGroupList":[],"nonTerminatingMatchingRules":[]}
{"timestamp":1795392001000,"action":"ALLOW","terminatingRuleId":"Default_Action","httpRequest":{"clientIp":"203.0.113.50","country":"GB","uri":"/v1/payments","httpMethod":"POST"},"ruleGroupList":[{"ruleGroupId":"AWS#AWSManagedRulesCommonRuleSet","nonTerminatingMatchingRules":[{"ruleId":"CrossSiteScripting_BODY","action":"COUNT"}]}],"nonTerminatingMatchingRules":[]}
{"timestamp":1795392002000,"action":"BLOCK","terminatingRuleId":"AWSManagedRulesAmazonIpReputationList","httpRequest":{"clientIp":"192.0.2.99","country":"NL","uri":"/.env","httpMethod":"GET"},"ruleGroupList":[],"nonTerminatingMatchingRules":[]}
{"timestamp":1795392003000,"action":"ALLOW","terminatingRuleId":"Default_Action","httpRequest":{"clientIp":"203.0.113.51","country":"GB","uri":"/v1/accounts/ACC-0000012345","httpMethod":"GET"},"ruleGroupList":[],"nonTerminatingMatchingRules":[]}

Run it with dotnet run -- sample-waf-logs.jsonl. Expected output (abridged):

Analysed 5 requests from sample-waf-logs.jsonl

Terminating rules:
  BLOCK    login-rate-limit                                   2
  ALLOW    Default_Action                                     2
  BLOCK    AWSManagedRulesAmazonIpReputationList              1

Counted (not blocked) matches — review before switching to Block:
  AWSManagedRulesCommonRuleSet:CrossSiteScripting_BODY              1

Top blocked client IPs:
  198.51.100.23         2  e.g. POST /v1/auth/login
  192.0.2.99            1  e.g. GET /.env

The CrossSiteScripting_BODY count on POST /v1/payments is the interesting line: a customer typed something like Rent <flat 2> in the payment reference. Switching the Core rule set to Block without a targeted override would reject a legitimate payment.

Code explained line by line

  1. WafLogRecord and friends are C# records with JsonPropertyName attributes mapping AWS's camelCase field names. Only fields you need are declared; System.Text.Json ignores the rest, which keeps the code resilient to new fields AWS adds.
  2. List<WafRuleGroup>? — nullable because some log records omit the property; the code uses ?? [] before iterating.
  3. File.ReadLines(path) streams the file line by line, so a multi-gigabyte S3 export does not need to fit in memory.
  4. The try/catch (JsonException) skips malformed lines instead of aborting — log exports sometimes contain truncated final lines.
  5. GroupBy(r => (r.Action, r.TerminatingRuleId)) uses a tuple key to count how many requests each rule ended, per action. Default_Action means no rule terminated the request.
  6. The counted query flattens two places where Count matches appear: inside managed rule groups (ruleGroupList[].nonTerminatingMatchingRules) and at web ACL level (nonTerminatingMatchingRules).
  7. ShortName turns a rule-group ID such as AWS#AWSManagedRulesCommonRuleSet into its readable name.
  8. The top-IP report only looks at blocked requests. The comment is deliberate: IP addresses can be personal data under UK GDPR, so treat the report like any other log extract.

Testing the rate limit locally? You can write a small HttpClient loop that sends 150 POST /v1/auth/login requests to your deployed lab stage and prints status codes. Expect the 429s to start only after a delay: WAF checks rates frequently but not instantly, and AWS documents that enforcement is approximate, so a few extra requests may get through. Never run load against an endpoint you do not own, and never against production without change approval — your load test is indistinguishable from an attack.

Security considerations

⚠ Learning shortcut — not for production

The lab uses a single regional web ACL, a 30-day log retention in the same account, and RemovalPolicy.DESTROY. In production: an edge web ACL on CloudFront plus a regional one, logs delivered to S3 in the log-archive account with retention set by your records-management policy, a Firewall Manager baseline policy, alarms on blocked-request spikes, and change control on every rule edit.

  • Never allow-list on spoofable data. X-Forwarded-For, User-Agent or a custom "internal caller" header can be set by anyone. If you aggregate rate limits on a forwarded IP header, configure it only when a trusted proxy (CloudFront) sets it.
  • Protect the origin from bypass. If CloudFront carries the WAF, make sure the API Gateway or ALB cannot be called directly — for example with a secret origin header verified by a regional web ACL, or with a VPC origin for ALBs.
  • Redact before storing. Authorization headers, session cookies, and query strings with customer identifiers must be redacted in logging configuration. Redaction affects logs only; it does not affect sampled requests or Security Lake collection, which have their own data-protection settings.
  • WAF is not authentication. Rate limiting login does not replace MFA, account lockout and risk-based authentication in your identity provider.
  • Fraud Control needs privacy review. ATP inspects submitted usernames and passwords (compared against a stolen-credentials database). Your DPO should review this processing; document it in the record of processing activities.
  • Shield Advanced contract. Subscribing commits the organisation for a year. Treat it as a procurement decision with finance sign-off, not a console click.

Banking use case

Harbourline's mobile-banking login receives about 40 requests per second at peak. In March, the fraud team sees a credential-stuffing campaign: 2 million login attempts in 6 hours from 30,000 residential proxy IPs, each IP sending only a handful of requests — too few to trip a per-IP rate limit.

The response, agreed by the fraud, security and digital teams:

ControlWhy it helpsCost consideration
Per-IP rate limit on /v1/auth/login (100 per 5 min)Stops naive attackers and misbehaving scriptsBase WAF only
ATP scoped to the login pathDetects requests with known-compromised credentials and volumetric patterns per session, adding labels you can block onSubscription plus a per-request fee; volume-based tiers make a scope-down essential
Bot Control (Targeted) with the WAF mobile SDKToken-based client verification distinguishes the real app from scriptsHigher per-request fee; requires app release
Step-up MFA in the identity provider for risky loginsDefeats the attack even if credentials are validIdentity platform cost
Alert to the fraud team on credential_compromised labelsCustomers whose credentials leaked elsewhere get a forced password resetOperational process

The architecture review notes that none of these controls makes the login "PCI compliant" or "PSD2 SCA compliant" by itself; Harbourline's compliance team maps each control to its obligations.

Common mistakes

  • Deploying managed rules straight to Block → legitimate payments rejected on day one → deploy in Count, review logs, override individual rules, then Block.
  • Using LogGroupArn from CDK for WAF logging → :* suffix rejected → build the ARN without it.
  • Log group name without the aws-waf-logs- prefix → logging configuration fails → rename.
  • Creating a CloudFront web ACL outside us-east-1 → it does not appear for association → CloudFront scope lives in us-east-1.
  • Per-IP limits set too low → mobile users behind carrier NAT are blocked → base limits on observed p99 per IP, and use header- or session-based aggregation where appropriate.
  • Expecting WAF to protect an HTTP API (API Gateway v2) directly → not supported → front it with CloudFront.
  • Subscribing to Shield Advanced "to try it" → one-year commitment → evaluate on paper first.

Troubleshooting

SymptomLikely causeFix
WAFInvalidParameterException on logging configDestination name lacks aws-waf-logs- or ARN ends with :*Rename the destination; strip the suffix
WAFLimitsExceededException creating the web ACLOver 5,000 WCUs, or rate-based rule count over 10Run check-capacity; remove or scope rules
Legitimate requests get 403 with no obvious ruleA managed group rule (e.g. SizeRestrictions_BODY) terminatedRead terminatingRuleId and ruleGroupList in logs; add a rule action override to Count for that rule
Rate limit never triggers in testingBelow the limit for the window, or traffic aggregated on a different key, or scope-down path mismatch (case)Check get-rate-based-statement-managed-keys; add a LOWERCASE transformation
429 arrives later than expectedRate checks are periodic and approximateExpected; design limits with margin
Web ACL not listed when associating a resourceWrong scope or RegionRegional resources need a REGIONAL web ACL in the same Region
Customers report CAPTCHA loops in the appCAPTCHA action on API calls from a native app without the WAF SDKUse Challenge/CAPTCHA only on browser flows, or integrate the mobile SDK

Cost and cleanup

Item (checked 2026-11-17)PriceLab exposure
Web ACLUSD 5.00 per month, prorated hourly2 hours ≈ USD 0.01
Rules (each managed group counts as one rule)USD 1.00 per rule per month, prorated5 rules × 2 h ≈ USD 0.01
RequestsUSD 0.60 per millionNegligible
WCUs above 1,500Extra USD 0.20 per million requests per 500 WCUsLab stays under 1,500
Bot Control Common / TargetedUSD 10 per month subscription each; per-request fees after free allowance (10M / 1M requests)Not used in lab
Fraud Control ATP / ACFPUSD 10 per month subscription each; tiered per-request fees starting around USD 1 per 1,000 requests after 10,000 freeNot used in lab
CloudWatch Logs ingestionStandard Logs pricingCents
Shield AdvancedUSD 3,000 per month, 1-year commitmentDesign only

Free alternative: skip deployment; run the WafLogReport program on the sample file and write the rules in CDK or Terraform, validated with cdk synth or terraform validate.

# CDK
cdk destroy --profile learn-sandbox

# Terraform
terraform destroy

# CLI-created resources
aws wafv2 delete-logging-configuration --resource-arn <web-acl-arn>
aws wafv2 disassociate-web-acl --resource-arn arn:aws:apigateway:us-east-1::/restapis/a1b2c3d4e5/stages/prod
LOCK=$(aws wafv2 get-web-acl --name hl-m05-accounts-api-acl --scope REGIONAL --id <id> --query LockToken --output text)
aws wafv2 delete-web-acl --name hl-m05-accounts-api-acl --scope REGIONAL --id <id> --lock-token "$LOCK"
aws logs delete-log-group --log-group-name aws-waf-logs-hl-m05-accounts-api

# Confirm nothing tagged for the lab remains, and that Shield Advanced is still INACTIVE
aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=cea-lab --query "ResourceTagMappingList[].ResourceARN"
aws shield get-subscription-state

Exercises

  • 🟢 Guided: Deploy the CDK stack in Count mode against your Module 4 lab API stage. Send 20 normal requests and 5 requests with ?id=1%27%20OR%201=1 in the query string. Export the log group and run WafLogReport on it. Which rule counted the SQL-injection probe?
  • 🟡 Challenge: Add a second rate-based rule that aggregates on a custom key: the x-harbourline-customer-id header combined with IP, limit 30 per minute on POST /v1/payments. Explain in two sentences why this is safe only if the header is set by your authorizer, not by the client.
  • 🔴 Live problem: Monday 08:05. The service desk says "online banking is slow and some customers see an error page". CloudWatch shows API Gateway 5xx rising, WAF AllowedRequests 20× normal, and requests spread across 40,000 IPs to GET /v1/accounts/{id} with random IDs. You do not have Shield Advanced. Decide what you would do in the first 30 minutes and what you would recommend afterwards.

Assignment

Create a "WAF rule register" for the Accounts API in your portfolio: one row per rule (priority, statement summary, action, owner, false-positive history, date last reviewed), the CDK stack, and a short decision record explaining whether Harbourline should buy Shield Advanced, with a cost comparison against the expected impact of a four-hour outage of online banking (use fictional figures and state your assumptions).

Solutions

Knowledge check

Interview questions

  • "How would you roll out WAF on an existing banking API without breaking customers?" — Inventory endpoints; deploy baseline managed groups in Count with logging and redaction; run representative traffic; review counted matches; override specific false-positive rules; switch to Block in stages with alarms; document every rule and owner.
  • "Is WAF enough to stop credential stuffing?" — No. It reduces volume (rate limits, ATP, bot control), but you also need MFA, risk-based authentication, breached-password checks, monitoring of login success rates, and customer notification processes.
  • "When would you recommend Shield Advanced?" — When downtime of internet-facing services has material financial or regulatory impact, there are multiple protected resources, the organisation wants 24/7 DDoS experts (SRT), cost protection and centrally managed WAF via Firewall Manager — and leadership accepts a one-year USD 3,000/month commitment.
  • "Where should WAF sit: CloudFront or ALB?" — Prefer the edge for absorption and global visibility, with origin-bypass protection; keep a regional ACL where traffic may reach the origin directly, or for internal ALBs exposed via other paths.

Certification practice

Completion checklist

  • I can explain web ACLs, rule priority, managed groups and WCUs in two sentences
  • I deployed a web ACL in Count mode, read the logs and understood each match
  • I wrote a rate-based rule with a custom ProblemDetails 429
  • I configured redaction of the Authorization header and query string
  • I can compare Shield Standard and Advanced, including cost and commitment
  • I destroyed the web ACL and log group and confirmed Shield Advanced is still inactive

Key takeaways

  • WAF filters HTTP requests to supported AWS resources; Shield Standard protects every customer at layers 3 and 4 at no cost.
  • Roll out managed rules in Count, tune with logs, then Block — banking payloads cause real false positives.
  • Rate-based rules need a scope-down, sensible limits (minimum 10, windows 1–10 minutes) and an understanding that enforcement is approximate.
  • Logs are evidence and also personal data: name them aws-waf-logs-…, redact secrets, and set retention.
  • Shield Advanced (USD 3,000/month, 1-year commitment) is a business decision about DDoS risk appetite, not a technical toggle. AWS protects its edge; Harbourline owns its rules, tuning and incident process.

Further reading

Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.

On this page