Skip to content

Commit

Permalink
Merge pull request #1205 from sharifhh/patch-2
Browse files Browse the repository at this point in the history
Update sqs-partial-batch-failure.md
  • Loading branch information
willfarrell authored Apr 20, 2024
2 parents 4bc82c4 + d7c03f2 commit e08344a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions website/docs/middlewares/sqs-partial-batch-failure.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ npm install --save-dev @aws-sdk/client-sqs

## Sample usage

Standrad Queue (All records handled in parallel):

```javascript
import middy from '@middy/core'
import sqsBatch from '@middy/sqs-partial-batch-failure'
Expand All @@ -35,6 +37,28 @@ const lambdaHandler = (event, context) => {
export const handler = middy().use(sqsBatch()).handler(lambdaHandler)
```

FIFO Queue (Records handled sequentially):

```javascript
import middy from '@middy/core'
import sqsBatch from '@middy/sqs-partial-batch-failure'

const lambdaHandler = (event, context) => {
const statusPromises = [];
for (const [idx, record] of Object.entries(Records)) {
try {
/* Custom message processing logic */
statusPromises.push(Promise.resolve());
} catch (error) {
statusPromises.push(Promise.reject(error));
}
}
return Promise.allSettled(statusPromises)
}

export const handler = middy().use(sqsBatch()).handler(lambdaHandler)
```

## Important

The value `ReportBatchItemFailures` must be added to your Lambda's `FunctionResponseTypes` in the `EventSourceMapping`. See [Reporting batch item failures](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting) and [Lambda EventSourceMapping](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)

0 comments on commit e08344a

Please sign in to comment.