One Stripe account, many side projects with EventBridge

8 min#aws #stripe #eventbridge #aws-cdk

Conversation cards and a routing sketch on a candlelit table. One Stripe account. Too many ideas. AWS EventBridge + CDK.

I’m 42, single, and back in the dating scene. It’s terrible, but somehow I turned that into Handsy, a card game for dates, and a Stripe Checkout flow for buying extra packs.

But… as a coder who is AI-pilled… there’s always another side-project idea behind the one I’m working on. A few of those ideas have made it out into the world, like RepFed, Local Bridge, Tower, MCPBuild, and Vault. For a little while I even had a software factory to make it easier to spin up the next app with AI agents giving me nightly prototypes based on my interests. Once I’d set up Stripe for Handsy, I wanted billing to be something I could reuse, too. A new Stripe account for every idea felt like a lot of ceremony.

Picture two checkouts on that one Stripe account. One person buys a card pack in Handsy. Another signs up for a subscription in a different app. How does each app know which event is its own? I didn’t want to create a webhook for each project. Instead… I put the project name on the relevant Stripe objects as metadata.project and used Amazon EventBridge to route events to each app’s Lambda. That let me start in one shared AWS account, with the option to give a product its own AWS account later.

Shared-account Stripe and EventBridge architecture for Handsy and RepFed

How I switched Handsy off its webhook

The part that made me nervous was giving EventBridge the job of unlocking the packs. Handsy already had a webhook doing that. Before I retired it, I wanted to see what would happen if both paths heard about the same purchase.

In May, I added the EventBridge consumer alongside the webhook… this was partly in preparation for something my friend Allen Helton wanted for his non-profit. We never did sync up on that… 😬 sorry, Allen.

For a while, a checkout.session.completed event tagged handsy could reach the code that grants the pack through either path. I could let both handlers make the same conditional write to DynamoDB because the grant was idempotent. The first one there could add the pack to ownedPacks. The second would find it already there and leave it alone.

In July, I ran a live-mode checkout on my own account with a 100%-off coupon. EventBridge picked it up, and I had one copy of the pack. Then I removed the webhook route and retired its destination in Stripe.

Handsy cutover flowchart showing both delivery paths active until EventBridge sees the purchase and Handsy grants one pack

When Stripe sent me back to /play, Handsy just reloaded my owned packs. I didn’t build a separate “pack incoming” screen for the cutover.

Handsy’s Checkout code leaves the payment methods to Stripe. For ACH or SEPA, I’d check payment_status before granting access on checkout.session.completed and wait for checkout.session.async_payment_succeeded if the Session is still unpaid.

Once I’d made the switch, I started using the same Stripe-to-EventBridge setup in other side projects. I put it in my AWS CDK starter template, too. Now when I get the itch to build something else, the routing is already there. I just have to decide what the app should do when somebody pays.

Where I put the project tag

Handsy sets metadata.project directly on the Checkout Session. Here’s the same thing with withProject from the package.

import { withProject } from "@martzmakes/stripe-events/runtime";

await stripe.checkout.sessions.create(
  withProject(
    {
      mode: "payment",
      line_items: [{ price: cardPackPriceId, quantity: 1 }],
      success_url: successUrl,
      cancel_url: cancelUrl,
    },
    "handsy",
  ),
);

If I want to route payment_intent.succeeded, I add the project tag in payment_intent_data.metadata when I create the Checkout Session. That event carries the PaymentIntent, which has its own metadata.

I set up RepFed’s billing back when it was called MacroVault, so its routing tag is still macrovault. RepFed writes the tag by hand alongside the email and billing plan, on the Session for Checkout and in subscription_data.metadata for subscription changes and cancellations. The snippet shows just the tag.

const project = "macrovault";

await stripe.checkout.sessions.create({
  mode: "subscription",
  line_items: [{ price: repfedProPriceId, quantity: 1 }],
  success_url: successUrl,
  cancel_url: cancelUrl,
  metadata: { project },
  subscription_data: { metadata: { project } },
});
When I care about…Stripe eventWhere I put or find the project
A customer finishing Checkoutcheckout.session.completedCheckout Session metadata.project
A PaymentIntent succeedingpayment_intent.succeededSet payment_intent_data.metadata.project on payment Checkout
A subscription changing or endingcustomer.subscription.*Set subscription_data.metadata.project on subscription Checkout
A subscription invoice getting paidinvoice.paidCheck parent.subscription_details.metadata.project in the invoice snapshot

In August I went back through the prototypes I had put live. Eight of them had switched to subscription Checkout with nothing listening for customer.subscription.deleted. A subscription could end and the app would still think you had paid access. I patched those eight apps, then added the event to both the rule and the Lambda in my CDK starter template.

What the Handsy rule matches

Stripe puts the snapshot under detail. This is the Handsy filter with an example partner source. It looks for checkout.session.completed and handsy in the Checkout Session’s metadata.

{
  "source": ["aws.partner/stripe.com/ed_example"],
  "detail-type": ["checkout.session.completed"],
  "detail": {
    "data": {
      "object": {
        "metadata": { "project": ["handsy"] }
      }
    }
  }
}

Testing a RepFed renewal

RepFed’s live billing Lambda handles Checkout and subscription lifecycle events. To see what happens with a paid renewal invoice, I tested a synthetic invoice.paid event using RepFed’s tag. Stripe copies the Subscription’s metadata into parent.subscription_details.metadata when it creates the invoice. The package’s standard consumer still checks metadata.project on the invoice itself, even with a nested extraEventPattern. I used a separate pattern for the invoice test.

I filter for subscription_cycle in billing_reason so I get renewals. Stripe uses subscription_create on the first invoice. For the access update, I’d key it by invoice ID so the handler can retry it safely.

Save the pattern as renewal-pattern.json.

{
  "source": [
    "aws.partner/stripe.com/ed_example"
  ],
  "detail-type": [
    "invoice.paid"
  ],
  "detail": {
    "data": {
      "object": {
        "billing_reason": [
          "subscription_cycle"
        ],
        "parent": {
          "subscription_details": {
            "metadata": {
              "project": [
                "macrovault"
              ]
            }
          }
        }
      }
    }
  }
}

Save this fixture as renewal-event.json.

{
  "version": "0",
  "id": "072a8b0d-46f0-43f6-a337-8de980d4f1ab",
  "source": "aws.partner/stripe.com/ed_example",
  "detail-type": "invoice.paid",
  "account": "123456789012",
  "time": "2026-11-19T13:00:00Z",
  "region": "us-east-1",
  "resources": [],
  "detail": {
    "id": "evt_renewal_example",
    "type": "invoice.paid",
    "data": {
      "object": {
        "id": "in_example",
        "billing_reason": "subscription_cycle",
        "parent": {
          "type": "subscription_details",
          "subscription_details": {
            "subscription": "sub_example",
            "metadata": {
              "project": "macrovault"
            }
          }
        }
      }
    }
  }
}
aws events test-event-pattern \
  --event-pattern file://renewal-pattern.json \
  --event file://renewal-event.json \
  --query Result

EventBridge matched the tagged renewal. It returned false for a different project, a missing tag, and subscription_create.

If a renewal invoice is missing the tag, I’d look up the Stripe subscription ID in my billing records. The same customer can pay for more than one app. I can backfill the tag on the Subscription for future invoices.

Getting the bus and the apps talking

There’s one shared stack for this. I gave StripeIngestion the pending partner source name from the AWS Region I set in Stripe Workbench. It associates the bus and writes the ARN and partner source name to Systems Manager Parameter Store for the app stacks. The example uses the test path.

import { StripeIngestion } from "@martzmakes/stripe-events";

new StripeIngestion(stack, "Stripe", {
  partnerSourceName: "aws.partner/stripe.com/ed_example",
  envName: "test",
});

The first time I tried deploying the RepFed rule, EventBridge rejected the partner bus name CDK passed in.

Meme about AWS providing a partner bus name, then rejecting that name in EventBusName

Passing the full bus ARN got the deploy through. RepFed still runs the tarball I pulled in with that fix. The snippet adapts its four-event filter to the npm release and points it at the test bus.

import { Duration } from "aws-cdk-lib";
import { Queue } from "aws-cdk-lib/aws-sqs";
import { StripeProjectConsumer } from "@martzmakes/stripe-events";

new StripeProjectConsumer(stack, "RepFedBilling", {
  envName: "test",
  project: "macrovault",
  eventTypes: [
    "checkout.session.completed",
    "customer.subscription.created",
    "customer.subscription.updated",
    "customer.subscription.deleted",
  ],
  handler: repfedBillingLambda,
  deadLetterQueue: new Queue(stack, "RepFedStripeDeliveryDlq", {
    retentionPeriod: Duration.days(7),
  }),
});

Testing the checkout filters

I checked the two filters with a synthetic Checkout event. Save the Handsy filter as pattern.json and this event as event.json. For a real sandbox capture, use its partner source in the filter.

{
  "version": "0",
  "id": "14c1e3d9-9d90-44cc-a0b0-85c70d867c49",
  "source": "aws.partner/stripe.com/ed_example",
  "detail-type": "checkout.session.completed",
  "account": "123456789012",
  "time": "2026-11-18T18:00:00Z",
  "region": "us-east-1",
  "resources": [],
  "detail": {
    "id": "evt_example",
    "type": "checkout.session.completed",
    "data": {
      "object": {
        "id": "cs_test_example",
        "payment_status": "paid",
        "metadata": { "project": "handsy" }
      }
    }
  }
}
aws events test-event-pattern \
  --event-pattern file://pattern.json \
  --event file://event.json \
  --query Result \
  --output json

With handsy on the event, the Handsy filter returned true. When I changed the tag to macrovault, the Handsy filter returned false and the RepFed filter matched.

The missing-tag pattern from StripeUnroutedEventsRule matched when I removed the tag. I also tried a deliberate typo, handys. It matched none of the three rules.

The bug in my own helper

Both Handsy and RepFed used my DynamoDB helper with event.detail.id, the ID Stripe puts inside the EventBridge event. Here’s the bit I don’t love about my own helper. It writes the claim before running the callback. If the callback throws, a retry or replay can see that claim and skip the work.

For a missing pack, I want to know whether to look at the EventBridge target dead-letter queue for a delivery failure or at Lambda’s own async retries and on-failure destination for an error after it accepted the event.

EventBridge delivery and Lambda retry paths

Next time I want the event claim and the grant in the same DynamoDB transaction. If the grant fails, the claim rolls back with it and the event can be retried.

When I’d split AWS or Stripe accounts

Handsy has its own CDK stack, so I can deploy it on its own. The apps still share AWS quotas, and anyone who can write rules on the bus can match another app’s events. The moment I’m handing an app to another operator or promising customers uptime, I want a separate AWS account for it.

Stripe is a billing decision. If an app needs its own name on receipts, its own payouts, or a different team handling refunds, that’s when I’d give it a separate Stripe account.

For these projects, my first move would be to split AWS and keep billing in one Stripe account. A partner bus in a central AWS account could forward events by project tag to each app’s bus. Each product would own its Lambda and its data.

Proposed cross-account EventBridge architecture for Handsy and RepFed

These apps had made $0. A separate AWS account for each one would have given me more infrastructure to debug before I knew if anyone would pay for it. I can write CDK stacks all day. So far, none of them has bought a card pack.

The repo has a runnable root stack and consumer if you want to try this with your own Stripe destination. GitHub examples · npm package

npm install @martzmakes/stripe-events aws-cdk-lib constructs

References

Matt Martz

@martzmakes.com

Coder/Dad Interested in 🍺, ❄️☕️, 🤖, 🚀, 💪, 🎲🧙‍♂️, 💻 I ♥️ CDK, Event Driven Architecture and Serverless #AWSCommunityBuilder

Mastodon: @martzmakes@martzmakes.com