Skip to content
GitHub Discord

AWS Workflow Bus

Creates an AWS Lambda durable workflow and triggers it with a Bus.

sst.config.ts
const workflow = new sst.aws.Workflow("MyWorkflow", {
handler: "src/workflow.handler",
});
const bus = new sst.aws.Bus("Bus");
bus.subscribe("Workflow", workflow, {
pattern: {
detailType: ["app.workflow.requested"],
},
});
const publisher = new sst.aws.Function("Publisher", {
handler: "src/publisher.handler",
url: true,
link: [bus],
});
src/workflow.ts
import { workflow } from "sst/aws/workflow";
interface Event {
"detail-type": string;
detail: {
properties: {
message: string;
};
};
}
export const handler = workflow.handler<Event>(async (event, ctx) => {
await ctx.step("start", async ({ logger }) => {
logger.info("Workflow invoked by bus.");
});
await ctx.wait("ten-seconds", { seconds: 10 });
await ctx.step("finish", async ({ logger }) => {
logger.info("Workflow finished.");
});
});
src/publisher.ts
import { Resource } from "sst";
import { bus } from "sst/aws/bus";
export async function handler() {
await bus.publish(Resource.Bus, "app.workflow.requested", {
message: "Hello from the bus",
requestId: `workflow-request-${Date.now()}`,
requestedAt: new Date().toISOString(),
});
return "Message published. Check the logs to see the workflow start.";
}

View the full example.