-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbackgroundWorkers.ts
More file actions
45 lines (38 loc) · 1.69 KB
/
backgroundWorkers.ts
File metadata and controls
45 lines (38 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Construct } from "constructs";
import { SharedProps } from "./constructs/sharedFunctionProps";
import { IEventBus } from "aws-cdk-lib/aws-events";
import { ITable } from "aws-cdk-lib/aws-dynamodb";
import { EventQueue } from "./constructs/eventQueue";
import { InstrumentedSqsLambdaFunction } from "./constructs/sqsLambdaFunction";
import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
import { Tags } from "aws-cdk-lib";
export interface BackgroundWorkerProps {
sharedProps: SharedProps;
bus: IEventBus;
table: ITable;
}
export class BackgroundWorker extends Construct {
constructor(scope: Construct, id: string, props: BackgroundWorkerProps) {
super(scope, id);
const orderSubmittedQueueName = "Kitchen-OrderSubmitted";
var queue = new EventQueue(this, "OrderSubmittedEventQueue", {
sharedProps: props.sharedProps,
bus: props.bus,
queueName: orderSubmittedQueueName,
eventSource: "https://orders.plantbasedpizza/",
detailType: "order.orderConfirmed.v1",
});
const orderConfirmedHandler = new InstrumentedSqsLambdaFunction(this, "HandleOrderConfirmedEvent", {
sharedProps: props.sharedProps,
handler: "index.handler",
buildDef: "./src/lambda/buildHandleOrderConfirmedEvent.js",
outDir: "./out/handleOrderConfirmedEvent",
functionName: "HandleOrderConfirmedEvent",
queue: queue.queue,
});
orderConfirmedHandler.function.addEnvironment("BUS_NAME", props.bus.eventBusName);
props.bus.grantPutEventsTo(orderConfirmedHandler.function);
props.table.grantReadWriteData(orderConfirmedHandler.function);
Tags.of(this).add("plantbasedpizza:application", "KitchenBackgroundWorker");
}
}