Clayton
07/25/2021, 7:54 PMFrank
thdxr
07/25/2021, 8:31 PMFrank
Clayton
07/26/2021, 8:06 PMFrank
Frank
Frontend → AppSync endpoint → SQS (optionally) → Lambda → Dynamo → Stream → Lambda → EventBridge → Rule → SQS → Lambda
Frank
thdxr
07/26/2021, 8:17 PMthdxr
07/26/2021, 8:19 PMnew events.Rule(this, "notifications_booked", {
eventBus: bus,
eventPattern: {
detailType: ["nori.calendar.booked"],
},
targets: [new targets.SqsQueue(queue)],
})
This could be made more ergonomicClayton
07/26/2021, 8:51 PMFrank
Topic
constructs where you can add Function
and Queue
subscribers to it. Something that looks like:
const myQueue = new sst.Queue(this, "MyQueue", {
consumer: "src/consumer.main"
});
new sst.Rule(this, "MyRule", {
eventBus: bus,
eventPattern: { .. },
targets: [
"src/lambda.main", // sst.Function target
myQueue, // sst.Queue target
],
});
thdxr
07/26/2021, 8:56 PMnew sst.RuleSet(this, "RuleSet", {
rules: [
{ pattern: { ... }, target(s): [...] },
{ pattern: { ... }, target(s): [...] },
{ pattern: { ... }, target(s): [...] }
}
})
That's probably not the best idea but illustrates the conceptthdxr
07/26/2021, 8:57 PMsst.API
allows you to specify all your routes instead of creating ApiGateway resources one by oneFrank
thdxr
07/26/2021, 9:00 PMconst func = new sst.Function(this, "notifications_booked_lambda", {
handler: "src/domains/notifications/booked.handler",
})
func.addToRolePolicy(
new iam.PolicyStatement({
actions: ["ses:SendEmail"],
resources: ["*"],
effect: iam.Effect.ALLOW,
})
)
new events.Rule(this, "notifications_booked", {
eventBus: bus,
eventPattern: {
detailType: ["nori.calendar.booked"],
},
targets: [new targets.LambdaFunction(func)],
})
Not sure if there's a less verbose way of writing this. Also often times the lambda target will also publish more events so I need to bus.grantPutEventsTo(func)
Frank
Frank
Clayton
07/26/2021, 11:27 PMFrank
EventBus
. Here are some examples - https://docs.serverless-stack.com/constructs/EventBusClayton
08/04/2021, 2:00 PM