Skip to content

TopicEventSource

Source: src/AWS/SNS/TopicEventSource.ts

Event source connecting an SNS Topic to the hosting Lambda function: it creates the lambda-protocol subscription (plus the invoke permission) at deploy time and dispatches delivered notifications to the registered handler at runtime.

The contract is a Binding.Service; the Lambda implementation layer is Lambda.TopicEventSource. Consume it through the consumeTopicNotifications helper.

export default WorkerFunction.make(
{ main: import.meta.url },
Effect.gen(function* () {
const topic = yield* SNS.Topic("Events");
// registers the subscription and the runtime dispatcher
yield* SNS.consumeTopicNotifications(topic, (stream) =>
stream.pipe(
Stream.runForEach((message) => Effect.log(message.Message)),
),
);
}).pipe(Effect.provide(Lambda.TopicEventSource)),
);