Skip to content
GitHub Discord

AWS Bus subscriptions

Subscribe bus events with AWS Lambda functions.

sst.config.ts
const bus = new sst.aws.Bus("Bus");
const publisher = new sst.aws.Function("Publisher", {
handler: "./src/publisher.handler",
url: true,
link: [bus],
});
bus.subscribe("Example", "./src/receiver.handler");
src/publisher.ts
import { bus } from "sst/aws/bus";
import { z } from "zod";
import { Resource } from "sst";
import { MyEvent } from "./events";
export async function handler() {
await bus.publish(Resource.Bus, MyEvent, { foo: "hello" });
return {
statusCode: 200,
};
}
src/receiver.ts
import { bus } from "sst/aws/bus";
import { MyEvent } from "./events";
export const handler = bus.subscriber([MyEvent], async (event) => {
console.log({ event });
});

View the full example.