Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sqs-partial-batch-failure.md #1205

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)