diff --git a/packages/batch/src/AsyncBatchProcessor.ts b/packages/batch/src/AsyncBatchProcessor.ts index 781c7f1c7..f4e02a327 100644 --- a/packages/batch/src/AsyncBatchProcessor.ts +++ b/packages/batch/src/AsyncBatchProcessor.ts @@ -10,7 +10,7 @@ class AsyncBatchProcessor extends BasePartialBatchProcessor { ): Promise { try { const data = this.toBatchType(record, this.eventType); - const result = await this.handler(data, this.options); + const result = await this.handler(data, this.options?.context); return this.successHandler(record, result); } catch (error) { diff --git a/packages/batch/src/BatchProcessor.ts b/packages/batch/src/BatchProcessor.ts index 3d2a75a8d..fdab0c6f4 100644 --- a/packages/batch/src/BatchProcessor.ts +++ b/packages/batch/src/BatchProcessor.ts @@ -19,7 +19,7 @@ class BatchProcessor extends BasePartialBatchProcessor { public processRecord(record: BaseRecord): SuccessResponse | FailureResponse { try { const data = this.toBatchType(record, this.eventType); - const result = this.handler(data, this.options); + const result = this.handler(data, this.options?.context); return this.successHandler(record, result); } catch (error) { diff --git a/packages/batch/tests/helpers/handlers.ts b/packages/batch/tests/helpers/handlers.ts index 3a6d17b76..0256129f9 100644 --- a/packages/batch/tests/helpers/handlers.ts +++ b/packages/batch/tests/helpers/handlers.ts @@ -3,7 +3,7 @@ import type { KinesisStreamRecord, SQSRecord, } from 'aws-lambda'; -import type { BatchProcessingOptions } from '../../src/types'; +import type { Context } from 'aws-lambda'; const sqsRecordHandler = (record: SQSRecord): string => { const body = record.body; @@ -63,12 +63,7 @@ const asyncDynamodbRecordHandler = async ( return body; }; -const handlerWithContext = ( - record: SQSRecord, - options: BatchProcessingOptions -): string => { - const context = options.context; - +const handlerWithContext = (record: SQSRecord, context: Context): string => { try { if (context.getRemainingTimeInMillis() == 0) { throw Error('No time remaining.'); @@ -82,10 +77,8 @@ const handlerWithContext = ( const asyncHandlerWithContext = async ( record: SQSRecord, - options: BatchProcessingOptions + context: Context ): Promise => { - const context = options.context; - try { if (context.getRemainingTimeInMillis() == 0) { throw Error('No time remaining.');