iaforek
iaforek

Reputation: 3108

How to simulate BatchWriteItem fail in DynamoDB?

How can I create a controlled BatchWriteItem fail in DynamoDB?

Basically, I want to have a way of simulating failure (break BatchWriteItem on purpose) in DynamoDB so I can make sure the logic that takes UnprocessedItems in response is working correctly.

From documentation: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html

Typically, you would call BatchWriteItem in a loop. Each iteration would check for unprocessed items and submit a new BatchWriteItem request with those unprocessed items until all items have been processed.

Below are two similar solutions discussed that use do-while loop and callback:

JAVA with do-while:

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/batch-operation-document-api-java.html

NODE with callback:

How to handle UnprocessedItems using AWS JavaScript SDK (dynamoDB)?

How to prepare a "broken" BatchWriteItem request in order to test this?

Can DynamoDB end up in infinite loop? i.e. BatchWriteItem returns UnprocessedItems, the code takes UnprocessedItems and calls BatchWriteItem and returns UnprocessedItems again and again?

Upvotes: 9

Views: 4416

Answers (1)

Bui Anh Tuan
Bui Anh Tuan

Reputation: 920

You will get failed BatchWriteItem when due to throttling on the individual tables. So if you want to test in this case, you must make your DynamoDB tables become throttling. Steps:

  1. Calculate Capacity write Unit of your DynamoDB table
  2. Implement a function which writes too many into DynamoDB and make it reach maximum Capacity Write Unit.
  3. Run your function BatchWriteItem. You will be able to get UnprocessedItems because your DynamoDb are throttling.

Upvotes: 4

Related Questions