Skip to content

EventSource

Source: src/AWS/Lambda/EventBridgeEventSource.ts

Lambda runtime implementation for AWS.EventBridge.events(...).subscribe(...).

This layer does two things:

  1. It delegates to EventSourcePolicy so deployment creates an EventBridge rule targeting the current Lambda function.
  2. At runtime it filters incoming Lambda events against the original event pattern and forwards matching events into the supplied Stream.
yield* AWS.EventBridge
.events({
source: ["app.user"],
"detail-type": ["UserCreated"],
})
.subscribe((events) =>
Stream.runForEach(events, (event) =>
Effect.log(`new user: ${event.detail.userId}`),
),
);
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}`),
),
);
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}`),
),
);
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}`),
),
);