Skip to content

Commit

Permalink
Switched to AWS Lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
bdougsand committed Nov 18, 2020
1 parent 14ee822 commit 3171d42
Show file tree
Hide file tree
Showing 9 changed files with 1,481 additions and 54 deletions.
27 changes: 27 additions & 0 deletions functions/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { APIGatewayEvent } from './src/types';

import * as beacon from './src';
import * as $u from './src/util';

export const handleSlackMessage = async (event: any, _context: any) => {
console.log('event', event);
for (const record of event.Records) {
await beacon.handleMessage(JSON.parse(record.body));
}
};

export const handleWebhook = (event: APIGatewayEvent, context: any) => {
const [,,, region, accountId] = context.invokedFunctionArn.split(':');
const queueName = process.env['QUEUE_NAME'];
const queueUrl = `https://sqs.${region}.amazonaws.com/${accountId}/${queueName}`;
const body = $u.parseBody(event);
console.log('event body:', body);

const req = {
body,
rawBody: event.body,
headers: event.headers,
};

return beacon.handleRequest(req, queueUrl);
};
Loading

0 comments on commit 3171d42

Please sign in to comment.