man@mndev:~/portfolio/notes/aws
← portfolio

Cross-account events with EventBridge and Lambda

Wiring two AWS accounts together with EventBridge: bus policies, rules, and the reliability details that matter in production.

AWS··2 min read

I needed changes in one product (users unsubscribing from saved searches) to reach a service that lived in another AWS account. Polling an API across accounts would work, but it couples the two teams’ uptime and deploys. EventBridge lets one side announce “this happened” and the other side react, without either knowing much about the other.

The shape

Account A (producer)                 Account B (consumer)
  app ──PutEvents──▶ bus A ──rule──▶ bus B ──rule──▶ Lambda

Three pieces make it work:

  1. A rule in account A that matches the event and targets the event bus ARN in account B. Give the rule an IAM role that allows events:PutEvents on that bus.
  2. A resource policy on bus B that lets account A put events.
  3. A rule in account B that routes the event to the Lambda handler.

The policy on bus B looks like this:

{
  "Sid": "AllowAccountA",
  "Effect": "Allow",
  "Principal": { "AWS": "arn:aws:iam::111111111111:root" },
  "Action": "events:PutEvents",
  "Resource": "arn:aws:events:us-east-1:222222222222:event-bus/consumer-bus"
}

Treat the event as a contract

The event’s source, detail-type and detail fields are a public API between two teams. I keep them:

Reliability details

EventBridge delivers at least once, so the handler must be idempotent. Processing the same unsubscribe twice should be harmless. Beyond that:

Testing it

Unit-test the handler with recorded sample events. Then add one end-to-end check in a non-production environment: put a test event in account A and assert that the side effect shows up in account B. That single test catches most permission and pattern mistakes, and those are where cross-account setups usually break.

// related