diff --git a/src/dynamo-streams.test.ts b/src/dynamo-streams.test.ts index 2995af3..da92a44 100644 --- a/src/dynamo-streams.test.ts +++ b/src/dynamo-streams.test.ts @@ -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, diff --git a/src/dynamo-streams.ts b/src/dynamo-streams.ts index 60c3e4b..6da8c28 100644 --- a/src/dynamo-streams.ts +++ b/src/dynamo-streams.ts @@ -159,13 +159,18 @@ export class DynamoStreamHandler { */ 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 = {