Skip to content

Commit

Permalink
feat: support non-http health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
swain committed Mar 16, 2022
1 parent e7be19f commit d555de6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/dynamo-streams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ describe('DynamoStreamHandler', () => {
});
});

test('responds to healthCheck events', async () => {
const lambda = new DynamoStreamHandler({
logger,
unmarshall: testSerializer.unmarshall,
createRunContext: () => ({}),
}).lambda();

const result = await lambda(
{ healthCheck: true } as any,
{} as any,
{} as any,
);

expect(result).toStrictEqual({
healthy: true,
});
});

test('handles insert events', async () => {
const lambda = new DynamoStreamHandler({
logger,
Expand Down
7 changes: 6 additions & 1 deletion src/dynamo-streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,18 @@ export class DynamoStreamHandler<Entity, Context> {
*/
lambda(): DynamoDBStreamHandler {
return async (event, ctx) => {
// 1. Handle the health check.
// 1. Handle potential health checks.
if ((event as any).httpMethod) {
return {
statusCode: 200,
body: JSON.stringify({ healthy: true }),
} as unknown as void;
}

if ((event as any).healthCheck) {
return { healthy: true } as any;
}

const correlationId = uuid();

const base: BaseContext = {
Expand Down

0 comments on commit d555de6

Please sign in to comment.