EventSource
Source:
src/AWS/Lambda/EventBridgeEventSource.ts
Lambda runtime implementation for AWS.EventBridge.events(...).subscribe(...).
This layer does two things:
- It delegates to
EventSourcePolicyso deployment creates an EventBridge rule targeting the current Lambda function. - At runtime it filters incoming Lambda events against the original event
pattern and forwards matching events into the supplied
Stream.
Subscribing To The Default Bus
Section titled “Subscribing To The Default Bus”yield* AWS.EventBridge .events({ source: ["app.user"], "detail-type": ["UserCreated"], }) .subscribe((events) => Stream.runForEach(events, (event) => Effect.log(`new user: ${event.detail.userId}`), ), );Subscribing To A Custom Bus
Section titled “Subscribing To A Custom Bus”const bus = yield* AWS.EventBridge.EventBus("OrdersBus", { name: "orders",});
yield* AWS.EventBridge .events(bus, { source: ["app.orders"], "detail-type": ["OrderPaid"], }) .subscribe((events) => Stream.runForEach(events, (event) => Effect.log(`paid order: ${event.detail.orderId}`), ), );Explicit Route Names
Section titled “Explicit Route Names”yield* AWS.EventBridge .events( "InvoiceEvents", { source: ["app.billing"], "detail-type": ["InvoiceIssued"], }, { description: "Deliver invoice events into this Lambda function", }, ) .subscribe((events) => Stream.runForEach(events, (event) => Effect.log(`invoice: ${event.detail.invoiceId}`), ), );Processing Typed Details
Section titled “Processing Typed Details”type UserCreated = { userId: string; email: string;};
yield* AWS.EventBridge .events({ source: ["app.user"], "detail-type": ["UserCreated"], }) .subscribe((events) => Stream.runForEach( events as Stream.Stream<AWS.EventBridge.EventRecord<UserCreated>>, (event) => Effect.log(`welcome ${event.detail.email}`), ), );