-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
event-bridge.ts
32 lines (29 loc) · 976 Bytes
/
event-bridge.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
import * as events from '@aws-cdk/aws-events';
import * as lambda from '@aws-cdk/aws-lambda';
import { Construct, Stack } from '@aws-cdk/core';
/**
* Use an Event Bridge event bus as a Lambda destination.
*
* If no event bus is specified, the default event bus is used.
*/
export class EventBridgeDestination implements lambda.IDestination {
/**
* @default - use the default event bus
*/
constructor(private readonly eventBus?: events.IEventBus) {
}
/**
* Returns a destination configuration
*/
public bind(_scope: Construct, fn: lambda.IFunction, _options?: lambda.DestinationOptions): lambda.DestinationConfig {
// deduplicated automatically
events.EventBus.grantPutEvents(fn); // Cannot restrict to a specific resource
return {
destination: this.eventBus && this.eventBus.eventBusArn || Stack.of(fn).formatArn({
service: 'events',
resource: 'event-bus',
resourceName: 'default',
}),
};
}
}