Repository navigation
Kill Switch
For operators: how to stop every request at the edge at once, how to turn it off again, and what the WAF does the rest of the time.
The kill switch blocks every request to an environment's CloudFront distribution: the site and the API alike. Use it when abuse or a cost run-up needs all traffic stopped at once. It is a rule in the WAF web ACL, defined in infra/modules/edge/main.tf, driven by one Terraform variable.
The web ACL compass-<env> always contains a rule named kill-switch at priority 5. Its statement matches every request (a URI path length of zero or more). Only its action changes:
kill_switch_enabled |
Rule action | Effect |
|---|---|---|
false (default) |
count |
Requests are counted and allowed. |
true |
block |
Every request gets HTTP 403 from the WAF. |
Nothing is created or destroyed when you flip it, so the plan is always one in-place change to the web ACL.
- Set the Terraform variable
kill_switch_enabledtotruein the HCP workspace of the environment. - Run
scripts/release.sh <env>(see Release). The plan must show one in-place change toaws_wafv2_web_acland nothing else. Typeyesfor dev orprodfor prod. - The change reaches the edge within a few minutes. Every request then gets HTTP 403, so the release script's health check fails after the apply and the script exits non-zero. That is expected while the switch is on.
- Set
kill_switch_enabledback tofalse, or remove the variable. - Run
scripts/release.sh <env>. The plan shows one in-place change to the web ACL. - Once the change has propagated,
GET /api/v1/healththrough CloudFront returns HTTP 200 and the health check passes.
- Apple passes already in a wallet stay on the phone and open offline. They stop updating while the switch is on.
- The
waf-blocked-requestsalarm fires while the switch is on, because every block counts (see Alarms). - WAF keeps no request samples and no logs by design, so there is no record of the blocked requests to review afterwards.
The API Gateway execute-api address cannot be called around CloudFront. Every API method requires the x-api-key header, and only CloudFront adds it, as a custom origin header. A direct call is refused by API Gateway before any Lambda runs. CloudFront also adds an x-origin-verify header that the Lambdas check before anything else, as a second layer. Blocking at the edge therefore stops all traffic.
The kill switch is one of eight rules. The others stay active whatever the switch says. Rate rules count requests per source IP over a five-minute window, in memory only.
| Priority | Rule | What it does |
|---|---|---|
| 1 | per-ip-rate-limit |
Blocks an IP above 600 requests on /api/*. |
| 2 | aws-managed-common |
AWS managed common rule set (its body size rule only counts; see below). |
| 3 | aws-managed-known-bad-inputs |
AWS managed known bad inputs rule set. |
| 4 | aws-managed-ip-reputation |
AWS managed IP reputation list. |
| 5 | kill-switch |
Counts every request, or blocks every request when the switch is on. |
| 6 | passkit-rate-limit |
Blocks an IP above 300 requests on /api/passkit/*. |
| 7 | api-body-size-limit |
Blocks any request body above 64 KB on /api/*. |
| 8 | site-per-ip-rate-limit |
Blocks an IP above 3,000 requests on every path outside /api/. |
The web ACL inspects request bodies up to 64 KB, and a larger body counts as oversize, which rule 7 blocks. Pass bodies can exceed the 8 KB body limit of the AWS common rule set, so that one rule (SizeRestrictions_BODY) is set to count; the API Gateway request validator and the Lambda schema checks bound the body instead. The rate limits are in infra/modules/edge/locals.tf.
Behind the WAF, API Gateway applies its own throttle: 50 requests a second with a burst of 100 across the stage, and tighter limits on the routes that write or cost more (for example 5 a second, burst 10, on POST /api/v1/passes, and 2 a second, burst 4, on DELETE /api/v1/me). These are the throttle_rate, throttle_burst and route_throttles variables in infra/envs/prod/variables.tf.
If only one feature is misbehaving, switch that feature off instead: Apple push, Google Wallet or the hand-off calendar download. They fail no request and leave the site up. See Alarms.
re:Invent Compass is an independent community project and is not affiliated with, endorsed by, or sponsored by Amazon Web Services. Boarding passes are unofficial: your re:Invent badge is your ticket. Licensed under Apache-2.0. Disclaimer · Repository · Project board
Get started
User guide
Architecture
- Overview
- Kiro Power
- MCP server
- Pass service
- Showcase site
- Flows
- AWS architecture
- Security
- Data and privacy
- Quality
Key decisions
- Index
- Product and scope
- Architecture
- Infrastructure
- Passes and wallets
- Security and privacy
- Delivery and tooling
Developer guide
Operations
Runbooks
How it was built
Reference
Links