-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs-to-eb-stack.ts
65 lines (58 loc) · 1.92 KB
/
logs-to-eb-stack.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as logs from 'aws-cdk-lib/aws-logs';
import * as destinations from 'aws-cdk-lib/aws-logs-destinations';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import * as busCdk from 'aws-cdk-lib/aws-events';
export class LogsToEbStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const DEFAULT_EVENT_BUS_NAME = 'slack';
// create a lambda function that writes the message to the log group
const messengerLambdaFunction = new NodejsFunction(
this,
'MessengerLambdaFunction',
{
functionName: 'Messenger',
runtime: lambda.Runtime.NODEJS_18_X,
entry: 'src/messenger.ts',
environment: {
DEFAULT_EVENT_BUS_NAME,
},
handler: 'handler',
}
);
let functionUrl = messengerLambdaFunction.addFunctionUrl({
authType: lambda.FunctionUrlAuthType.AWS_IAM,
});
const bridgifyFunction = new NodejsFunction(
this,
'BridgifyLambdaFunction',
{
functionName: 'Bridgify',
runtime: lambda.Runtime.NODEJS_18_X,
memorySize: 512,
entry: 'src/bridgify.ts',
handler: 'handler',
}
);
const subscriptionFilter = new logs.SubscriptionFilter(
this,
'SubscriptionFilter',
{
logGroup: messengerLambdaFunction.logGroup,
filterName: 'eventBridgeFilter',
destination: new destinations.LambdaDestination(bridgifyFunction),
filterPattern: logs.FilterPattern.literal('EVENT_BRIDGE'),
}
);
const bus = new busCdk.EventBus(this, 'SlackEventBus', {
eventBusName: DEFAULT_EVENT_BUS_NAME,
});
bus.grantPutEventsTo(bridgifyFunction);
new cdk.CfnOutput(this, 'FunctionUrl', {
value: functionUrl.url,
});
}
}