Skip to content

In batchItemFailures, itemIdentifier should be record.eventID or record.dynamo.SequenceNumber?

0

Hello,

I need advise whether in batchItemFailures for DynamoDB lambda, itemIdentifier should be record.eventID or record.dynamo.SequenceNumber?

Many examples on github use record.dynamo.SequenceNumber but some use record.eventID. Different AIs recommend different usage.

Unfortunately, I did not find official AWS documentation with exact specification of this.

Here, it is mentioned as just SequenceNumber. "Configuring partial batch response with DynamoDB and Lambda" https://docs.aws.amazon.com/lambda/latest/dg/services-ddb-batchfailurereporting.html

{ 
  "batchItemFailures": [ 
        {
            "itemIdentifier": "<SequenceNumber>"
        }
    ]
}

Also, please advise partial batch failure format for Kafka lambda. Here, in official document , it is describes as following :"Configuring error handling controls for Kafka event sources" - https://docs.aws.amazon.com/lambda/latest/dg/kafka-retry-configurations.html#kafka-partial-batch-response

{
  "batchItemFailures": [
    {
      "itemIdentifier": {
        "topic-partition": "topic-partition_number",
        "offset": 100
      }
    },
    ...
  ]
}

While some AI 's advise the following:

{
  "batchItemFailures": [
    {  "itemIdentifier": "topic-partition_number-offset"},
    ...
  ]
}

Thank you, Sam

asked 10 months ago125 views

1 Answer
0

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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.