Skip to content

Commit f561c1c

Browse files
committed
doc: async sqs fifo message processing
1 parent a425e81 commit f561c1c

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

docs/utilities/batch.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,27 @@ Enable the `skipGroupOnError` option for seamless processing of messages from va
149149

150150
=== "Recommended"
151151

152-
```typescript hl_lines="1-4 8"
152+
```typescript hl_lines="1-4 8 20"
153153
--8<-- "examples/snippets/batch/gettingStartedSQSFifo.ts"
154154
```
155155

156156
1. **Step 1**. Creates a partial failure batch processor for SQS FIFO queues. See [partial failure mechanics for details](#partial-failure-mechanics)
157157

158+
=== "Async processing"
159+
160+
```typescript hl_lines="1-4 8 20"
161+
--8<-- "examples/snippets/batch/gettingStartedSQSFifoAsync.ts"
162+
```
163+
158164
=== "Enabling skipGroupOnError flag"
159165

160166
```typescript hl_lines="1-4 13 30"
161167
--8<-- "examples/snippets/batch/gettingStartedSQSFifoSkipGroupOnError.ts"
162168
```
163169

164170
!!! Note
165-
Note that SqsFifoPartialProcessor is synchronous using `processPartialResponseSync`.
166-
This is because we need to preserve the order of messages in the queue. See [Async or sync processing section](#async-or-sync-processing) for more details.
171+
Note that `SqsFifoPartialProcessor` is synchronous using `processPartialResponseSync`.
172+
If you need asynchronous processing while preserving the order of messages in the queue, use `SqsFifoPartialProcessorAsync` with `processPartialResponse`.
167173

168174
### Processing messages from Kinesis
169175

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {
2+
SqsFifoPartialProcessorAsync,
3+
processPartialResponse,
4+
} from '@aws-lambda-powertools/batch';
5+
import { Logger } from '@aws-lambda-powertools/logger';
6+
import type { SQSHandler, SQSRecord } from 'aws-lambda';
7+
8+
const processor = new SqsFifoPartialProcessorAsync();
9+
const logger = new Logger();
10+
11+
const recordHandler = async (record: SQSRecord): Promise<void> => {
12+
const payload = record.body;
13+
if (payload) {
14+
const item = JSON.parse(payload);
15+
logger.info('Processed item', { item });
16+
}
17+
};
18+
19+
export const handler: SQSHandler = async (event, context) =>
20+
processPartialResponse(event, recordHandler, processor, {
21+
context,
22+
});

0 commit comments

Comments
 (0)