- Newest
- Most votes
- Most comments
For DynamoDB streams with Lambda, the itemIdentifier in batchItemFailures should be the record's dynamodb.SequenceNumber.
According to the AWS documentation, when configuring reporting on batch item failures with DynamoDB and Lambda, you need to return the sequence number of the failed record in the batch. The required response syntax shows that the itemIdentifier should contain the SequenceNumber.
This is consistently demonstrated in the code examples across multiple programming languages. For instance, in JavaScript:
export const handler = async (event) => { const records = event.Records; let curRecordSequenceNumber = ""; for (const record of records) { try { // Process your record curRecordSequenceNumber = record.dynamodb.SequenceNumber; } catch (e) { // Return failed record's sequence number return { batchItemFailures: [{ itemIdentifier: curRecordSequenceNumber }] }; } } return { batchItemFailures: [] }; };
Similarly, in TypeScript, Go, and other languages, the examples consistently use record.dynamodb.SequenceNumber (or the equivalent in that language) as the value for itemIdentifier.
The SequenceNumber is the correct identifier to use because it's what Lambda uses to track the position in the DynamoDB stream and determine which records to retry when processing fails.
Sources
Configuring partial batch response with DynamoDB and Lambda - AWS Lambda
DynamoDB examples using SDK for JavaScript (v3) - AWS SDK Code Examples
Lambda examples using SDK for JavaScript (v3) - AWS SDK Code Examples
Reporting batch item failures for Lambda functions with a DynamoDB trigger - AWS SDK Code Examples
Reporting batch item failures for Lambda functions with a DynamoDB trigger - AWS SDK Code Examples
answered 10 months ago
Relevant content
asked a year ago
- AWS OFFICIALUpdated 2 years ago
