1- import { SQSBatchItemFailure , SQSEvent , SQSHandler } from "aws-lambda" ;
1+ import { SQSBatchItemFailure , SQSEvent , SQSHandler , Context } from "aws-lambda" ;
22import { $LetterRequestPreparedEvent } from "@nhsdigital/nhs-notify-event-schemas-letter-rendering-v1" ;
33import {
44 InsertLetter ,
@@ -25,6 +25,10 @@ import {
2525 UpsertOperation ,
2626} from "./schemas" ;
2727
28+ const idempotencyConfig = new IdempotencyConfig ( {
29+ eventKeyJmesPath : "id" ,
30+ } ) ;
31+
2832function getOperationFromType ( type : string ) : UpsertOperation {
2933 if (
3034 type . startsWith ( "uk.nhs.notify.letter-rendering.letter-request.prepared" )
@@ -187,7 +191,7 @@ function parseQueueMessage(queueMessage: string): QueueMessage {
187191export default function createUpsertLetterHandler ( deps : Deps ) : SQSHandler {
188192 const processRecordIdempotently = makeIdempotentOnId ( processRecord , deps ) ;
189193 return metricScope ( ( metrics : MetricsLogger ) => {
190- return async ( event : SQSEvent ) => {
194+ return async ( event : SQSEvent , context : Context ) => {
191195 const batchItemFailures : SQSBatchItemFailure [ ] = [ ] ;
192196 const perSupplierSuccess : Map < string , number > = new Map < string , number > ( ) ;
193197 const perSupplierFailure : Map < string , number > = new Map < string , number > ( ) ;
@@ -222,6 +226,7 @@ export default function createUpsertLetterHandler(deps: Deps): SQSHandler {
222226 supplier : supplierSpec ,
223227 } ) ;
224228
229+ idempotencyConfig . registerLambdaContext ( context ) ;
225230 supplier = await processRecordIdempotently (
226231 letterEvent ,
227232 supplierSpec ,
@@ -283,8 +288,6 @@ async function processRecord(
283288function makeIdempotentOnId ( fn : AnyFunction , deps : Deps ) {
284289 return makeIdempotent ( fn , {
285290 persistenceStore : deps . idempotencyLayer ,
286- config : new IdempotencyConfig ( {
287- eventKeyJmesPath : "id" ,
288- } ) ,
291+ config : idempotencyConfig ,
289292 } ) ;
290293}
0 commit comments