Commit 99148d3
feat(infra): DynamoDB-backed rate limiting + CDK table
Per the AWS-native stack (matches SES). server/lib/rateLimit.ts now has one
async API over two backends:
- DynamoDB (when RATE_LIMIT_TABLE is set): atomic fixed-window counters with
native TTL; fail-open on errors so a misconfigured table can't take the site
down. AWS SDK clients added (@aws-sdk/client-dynamodb + lib-dynamodb).
- in-memory sliding window for local dev / fallback.
Helper `enforceRateLimit({ key, limit, windowMs, message })` throws
TOO_MANY_REQUESTS; search / content.create / sponsor.submit now await it.
CDK: StorageStack provisions the rate-limit DynamoDB table (pk + ttl,
PAY_PER_REQUEST, retain on prod) and publishes its name to SSM
/env/rate-limit-table + a CfnOutput. App env needs RATE_LIMIT_TABLE = that name
and dynamodb:UpdateItem on the table.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent abc89a2 commit 99148d3
7 files changed
Lines changed: 883 additions & 167 deletions
File tree
- cdk/lib
- server
- api/router
- lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
33 | 61 | | |
34 | 62 | | |
35 | 63 | | |
| |||
0 commit comments