Error: DynamoDB BatchWriteItem error

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
BatchWriteItem can reject an invalid request or return a successful response with writes still in UnprocessedItems. Check both the exception and the response body. A batch supports puts and deletes, not updates or per-item conditions.
Fix request validation first
- Send at most 25 operations across all tables in one request. The request can contain up to 16 MB of transmitted data; each stored item must fit 400 KB. These are separate limits.
- Include the complete primary key with matching attribute types. A DeleteRequest contains only the table key, including the sort key when the table has one.
- Remove duplicate operations on the same full primary key within a batch, including a put and delete of the same item.
- Confirm the table exists in the client’s account, Region, and endpoint. A backup does not block writes, and an UPDATING table does not universally reject them. Deleting an absent item is allowed.
Handle partially processed batches
This SDK v3 example uses ordinary JavaScript values with DynamoDBDocumentClient. It resubmits only unprocessed writes, uses jitter, and stops after a bounded number of application retries. The numeric retry settings below are example application policy, not DynamoDB limits.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, BatchWriteCommand } from "@aws-sdk/lib-dynamodb";
import { setTimeout as sleep } from "node:timers/promises";
const db = DynamoDBDocumentClient.from(new DynamoDBClient({ region: "us-east-1" }));
let pending = { Orders: [
{ PutRequest: { Item: { pk: "ORDER#123", sk: "DETAIL", status: "NEW" } } },
{ DeleteRequest: { Key: { pk: "ORDER#456", sk: "DETAIL" } } }
] };
for (let attempt = 0; attempt < 6 && Object.keys(pending).length; attempt++) {
const result = await db.send(new BatchWriteCommand({ RequestItems: pending }));
pending = result.UnprocessedItems ?? {};
if (Object.keys(pending).length) {
await sleep(Math.random() * Math.min(2000, 100 * 2 ** attempt));
}
}
if (Object.keys(pending).length) {
throw new Error("Batch incomplete; retain pending writes for recovery");
}SDK retries handle retryable request exceptions; they do not drain a successful response’s UnprocessedItems for you. If the request itself throws after SDK retries, propagate the error and retain the work for recovery. Avoid replaying already completed puts if another writer may have changed those items.
For persistent throttling, inspect the affected table or GSI and spread writes across keys. Batch writes are not atomic as a group. Use individual conditional writes or a transaction when correctness depends on conditions or all-or-nothing behavior.
See batch write patterns and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB scan filter expression not working
- DynamoDB Update Not Working
- dynamodb unknown error
- dynamodb could not connect to the endpoint url
- DynamoDB Duplicate Key Error
- DynamoDB Invalid UpdateExpression Syntax Error Token
- dynamodb-admin command not found
- dynamodb could not instantiate class
- Float types are not supported. Use decimal types instead.
- DynamoDB Query Limit Not Working
- dynamodb 1 validation error detected value
- dynamodb table did not stabilize
- ImportError: No module named boto3 (DynamoDB)
- dynamodb put function not working
- Conditional Update Error DynamoDB
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today