Search code examples
amazon-web-servicesaws-lambdaamazon-dynamodb

DynamoDB BatchWriteItem: Provided list of item keys contains duplicates


I am trying to use DynamoDB operation BatchWriteItem, wherein I want to insert multiple records into one table.

This table has one partition key and one sort key.

I am using AWS lambda and Go language.

I get the elements to be inserted into a slice.

I am following this procedure.

  1. Create PutRequest structure and add AttributeValues for the first record from the list.

  2. I am creating WriteRequest from this PutRequest

  3. I am adding this WriteRequest to an array of WriteRequests

  4. I am creating BatchWriteItemInput which consists of RequestItems, which is basically a map of Tablename and the array of WriteRequests.

After that I am calling BatchWriteItem, which results into an error:

Provided list of item keys contains duplicates.

Any pointers, why this could be happening?


Solution

  • You've provided two or more items with identical primary keys (which in your case means identical partition and sort keys).

    Per the BatchWriteItem docs, you cannot perform multiple operations on the same item in the same BatchWriteItem request.