Skip to content

Commit e945093

Browse files
committed
docs(batch): added new option to dosc
1 parent db1a541 commit e945093

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

docs/utilities/batch.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ All records in the batch will be passed to this handler for processing, even if
261261

262262
* **All records successfully processed**. We will return an empty list of item failures `{'batchItemFailures': []}`
263263
* **Partial success with some exceptions**. We will return a list of all item IDs/sequence numbers that failed processing
264-
* **All records failed to be processed**. We will raise `BatchProcessingError` exception with a list of all exceptions raised when processing. This exception can be bypassed if you set `throwOnFullBatchFailure` option to `false`.
264+
* **All records failed to be processed**. We will throw a `FullBatchFailureError` error with a list of all the errors thrown while processing unless `throwOnFullBatchFailure` is disabled.
265265

266266
The following sequence diagrams explain how each Batch processor behaves under different scenarios.
267267

@@ -450,6 +450,18 @@ We can automatically inject the [Lambda context](https://docs.aws.amazon.com/lam
450450
--8<-- "examples/snippets/batch/accessLambdaContext.ts"
451451
```
452452

453+
### Working with full batch failures
454+
455+
By default, the `BatchProcessor` will throw a `FullBatchFailureError` if all records in the batch fail to process, we do this to reflect the failure in your operational metrics.
456+
457+
In some cases, for example such as when working with small batches or when using errors as flow control mechanism, this behavior might not be desired and end up negatively impacting the concurrency of your function.
458+
459+
For these scenarios, you can set the `throwOnFullBatchFailure` option to `false` when calling.
460+
461+
```typescript hl_lines="17"
462+
--8<-- "examples/snippets/batch/noThrowOnFullBatchFailure.ts"
463+
```
464+
453465
### Extending BatchProcessor
454466

455467
You might want to bring custom logic to the existing `BatchProcessor` to slightly override how we handle successes and failures.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
BatchProcessor,
3+
EventType,
4+
processPartialResponse,
5+
} from '@aws-lambda-powertools/batch';
6+
import type { SQSHandler, SQSRecord } from 'aws-lambda';
7+
8+
const processor = new BatchProcessor(EventType.SQS);
9+
10+
const recordHandler = async (_record: SQSRecord): Promise<void> => {
11+
// Process the record
12+
};
13+
14+
export const handler: SQSHandler = async (event, context) =>
15+
processPartialResponse(event, recordHandler, processor, {
16+
context,
17+
throwOnFullBatchFailure: false,
18+
});

packages/batch/src/BasePartialBatchProcessor.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ abstract class BasePartialBatchProcessor extends BasePartialProcessor {
6363
/**
6464
* Clean up logic to be run after processing a batch
6565
*
66-
* If the entire batch failed, and `throwOnFullBatchFailure` option is not explicitly
67-
* set to `false`, this method will throw a `FullBatchFailureError` with the list of
68-
* errors that occurred during processing.
66+
* If the entire batch failed this method will throw a {@link FullBatchFailureError | `FullBatchFailureError`} with the list of
67+
* errors that occurred during processing, unless the `throwOnFullBatchFailure` option is set to `false`.
6968
*
7069
* Otherwise, it will build the partial failure response based on the event type.
7170
*/

0 commit comments

Comments
 (0)