Skip to content

Publish

Source: src/AWS/SNS/Publish.ts

Runtime binding for sns:Publish.

Bind this operation to a Topic inside a function runtime to get a callable that automatically injects the TopicArn. The binding grants the host function sns:Publish on the topic. Provide the PublishHttp layer on the Function to implement the binding.

export class ApiFunction extends Lambda.Function<Lambda.Function>()(
"ApiFunction",
) {}
export default ApiFunction.make(
{ main: import.meta.url, url: true },
Effect.gen(function* () {
const topic = yield* SNS.Topic("Events");
// init: bind the operation to the topic (grants sns:Publish)
const publish = yield* SNS.Publish(topic);
return {
fetch: Effect.gen(function* () {
// runtime: TopicArn is injected automatically
const response = yield* publish({
Message: "order shipped",
Subject: "order-update",
});
return yield* HttpServerResponse.json({
messageId: response.MessageId,
});
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(SNS.PublishHttp)),
);