-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessenger.ts
29 lines (29 loc) · 1.01 KB
/
messenger.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
import { APIGatewayEvent, Handler } from 'aws-lambda';
import { PutEventsCommand } from '@aws-sdk/client-eventbridge';
export const handler: Handler = async (event: APIGatewayEvent, context) => {
let parsedBody = JSON.parse(event.body!);
if (parsedBody.message) {
let putEventsCommand = new PutEventsCommand({
Entries: [
{
EventBusName: process.env.DEFAULT_EVENT_BUS_NAME!,
Source: `cc.speedrun.${context.functionName}`,
DetailType: 'Lambda Function Invocation',
Detail: JSON.stringify({ message: parsedBody.message }),
},
],
});
console.log('EVENT_BRIDGE: ' + JSON.stringify(putEventsCommand.input));
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'Message sent to EventBridge' }),
};
} else {
return {
statusCode: 400,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ error: 'No message found' }),
};
}
};