Migrate seller from Lambda@Edge to native CloudFront + WAF x402 monetization#30
Draft
arditti wants to merge 9 commits into
Draft
Migrate seller from Lambda@Edge to native CloudFront + WAF x402 monetization#30arditti wants to merge 9 commits into
arditti wants to merge 9 commits into
Conversation
Update seller-infrastructure README/bin description, docs/API.md, docs/TROUBLESHOOTING.md, QUICKSTART.md, and payer-infrastructure observability dashboards + IAM comments to describe the CloudFront + AWS WAF native x402 monetization architecture (Bot Control v6, human-allow, free discovery, per-tier Monetize + MonetizationConfig) that replaced the Lambda@Edge payment verifier.
AWS WAF AI traffic monetization requires the base price to be >= $0.001 USDC with at most 3 decimal places (per the getting-started + pricing docs). The previous $0.0005 base violated both the minimum and the 3-decimal rule. Rebase to a $0.001 base and re-derive integer tier multipliers from the original prices (market x2, tutorial x3, research x5, dataset x10); the sub-minimum weather price floors to the base (x1). Update tests + docs and add a base-price compliance assertion. Ref: https://docs.aws.amazon.com/waf/latest/developerguide/waf-ai-traffic-monetization-pricing.html
…ending The AWS WAF AI traffic monetization capability is generally available (configurable via the WAF console and API today). Only the MonetizationConfig / Monetize fields in the released CloudFormation / CDK / SDK (and Terraform AWS provider) are still pending, expected to follow shortly. Reword comments/docs accordingly: the L1 addPropertyOverride (or commented HCL) is the supported way to set these fields until the typed props land — not a 'preview'/'inert' workaround.
A live deploy proved the ByteMatchStatement SearchString was being double-base64-encoded: the builder base64'd the prefix AND CloudFormation base64's it again, so the deployed rule searched for the literal text 'L2RhdGFzZXQ=' and never matched. Every request fell through to the default Allow and no 402 was ever issued. Fix: emit the plain URI prefix (e.g. '/dataset'); CloudFormation does the single base64 encoding the WAF API requires. Add a regression test asserting plain SearchString. Verified end-to-end on a live deploy (account 638769857148, us-east-1): bot -> 402 challenge (/bin/zsh.01 dataset tier, correct payee) -> EIP-3009 payment -> 200 + content -> on-chain settlement of 0.01 USDC on Base Sepolia (payer -0.01, seller +0.01).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace Lambda@Edge payment verifier with native CloudFront + WAF x402 monetization
AWS WAF AI traffic monetization is now GA. This PR migrates
seller-infrastructure/off the custom Lambda@Edge verifier and onto a WAF WebACL with
MonetizationConfig+per-route
Monetizerules — charging AI bots for content natively at the edge, no Lambda.Changes
cloudfront.experimental.EdgeFunctionpayment verifier andlib/lambda-edge/.human-allow(humans free),free discovery (
/mcp/*,/.well-known/*), and per-tierMonetizerules reproducingthe original prices ($0.001–$0.01, Base Sepolia USDC) off a $0.001 base ×
PriceMultiplier.docs/native-waf-x402-migration.md.✅ Validated end-to-end on a live deploy
Deployed to a real AWS account (us-east-1) and ran the full flow against the GA capability:
MonetizationConfig+Monetizeactions deploys via CloudFormation andattaches to the distribution (confirmed via
get-web-acl).10000=$0.01 for the dataset tier ×10, correct payee, Base Sepolia USDC,
x402Version: 2).human-allow); discovery path → not monetized.payer −0.010000 USDC, seller +0.010000 USDC. 🎉
🐛 Bug found & fixed by the live deploy
The first deploy served 200 (free) for everything — no 402. Root cause: the
ByteMatchStatement.SearchStringwas double-base64-encoded (the builder base64'd theprefix, and CloudFormation base64's it again), so rules searched for the literal text
L2RhdGFzZXQ=and never matched — every request fell through to the default Allow. Fixedto emit the plain URI prefix (CFN does the single encoding the WAF API needs) +
regression test. Unit tests alone had baked in the bug; only the live deploy caught it.
Spec compliance
Checked against the AWS WAF AI traffic monetization docs
(getting started,
pricing):
MonetizationConfigshape matches;Chain=BASE_SEPOLIA+CurrencyMode=TESTvalid;base price ≥ the $0.001 minimum (≤3 dp);
Monetizeterminating + bot-gated;PriceMultiplier1–100 integer-as-string.IaC support status / gating
The
Monetizeaction +MonetizationConfigare in the CloudFormationAWS::WAFv2::WebACLschema and deploy correctly (verified end-to-end above). Thetyped CDK L2/L1 props are not in
aws-cdk-libyet (latest checked: 2.260.0 — nomonetization typings), so this PR sets the fields via the L1
addPropertyOverrideescapehatch, which emits exactly the CFN that deploys today. When the typed CDK props ship, the
override can be simplified to native props with no behavioral change. Marked draft
pending that cosmetic follow-up and maintainer review; functionally it is validated and
deployable now.