-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy patheventbus.ts
44 lines (34 loc) · 1.43 KB
/
eventbus.ts
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
import { EventBus, Rule } from "aws-cdk-lib/aws-events";
import { SqsQueue } from "aws-cdk-lib/aws-events-targets";
import { IFunction } from "aws-cdk-lib/aws-lambda";
import { IQueue } from "aws-cdk-lib/aws-sqs";
import { Construct } from "constructs";
interface SwnEventBusProps {
publisherFuntion: IFunction;
targetQueue: IQueue;
}
export class SwnEventBus extends Construct {
constructor(scope: Construct, id: string, props: SwnEventBusProps) {
super(scope, id);
//eventbus
const bus = new EventBus(this, 'SwnEventBus', {
eventBusName: 'SwnEventBus'
});
const checkoutBasketRule = new Rule(this, 'CheckoutBasketRule', {
eventBus: bus,
enabled: true,
description: 'When Basket microservice checkout the basket',
eventPattern: {
source: ['com.swn.basket.checkoutbasket'],
detailType: ['CheckoutBasket']
},
ruleName: 'CheckoutBasketRule'
});
// // need to pass target to Ordering Lambda service
// checkoutBasketRule.addTarget(new LambdaFunction(props.targetFuntion));
// need to pass target to Ordering Lambda service
checkoutBasketRule.addTarget(new SqsQueue(props.targetQueue));
bus.grantPutEventsTo(props.publisherFuntion);
// AccessDeniedException - is not authorized to perform: events:PutEvents
}
}