Handling DynamoDB BatchWrite Errors in Node.js

So, you’re building a Node.js app to do DynamoDB Batch Writes or better yet, you’re diving into AWS’ Lambda? You want to be a good programmer and handle errors gracefully, right? You came to the right place.

First, how do errors look? Notice how you just get an empty {} when all is good, well here is it how it looks if any items are unprocessed by DynamoDB:

Now, this is really cool because Amazon just perfectly returned all the code you need to do a new batch write.
All you need to do now is write a callback and ideally put in some exponential backoff logic, like so:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.