7

According to this aws doc http://docs.aws.amazon.com/general/latest/gr/api-retries.html automatic retry feature is build in the aws sdk in my case node.js aws sdk. I configured the DocumentClient object like this:

var dynamodb = new AWS.DynamoDB.DocumentClient({
    region: 'us-west-2',
    retryDelayOptions: {base: 50},
    maxRetries: 20
});

but I still cannot make it auto-retry for me. I want to auto-retry with all UnprocessedItems as well. Can you point me to where is my mistake?

Thanks

3 Answers 3

9

The retryDelayOptions and maxRetries are the options present on AWS.DynamoDB. The DocumentClient has to be configured by setting the DynamoDB service.

var dynamodb = new AWS.DynamoDB({maxRetries: 5, retryDelayOptions: {base: 300} });
var docClient = new AWS.DynamoDB.DocumentClient({service : dynamodb});
Sign up to request clarification or add additional context in comments.

Comments

7

The AWS Client SDKs all have built-in mechanisms for retry indeed, however those retries are at the request level. That means that any request that gets rejected by the server with a 500-level error, or in some cases, a 400-level throttling error will get automatically retried based on the configured settings.

What you are asking for is business-layer retry behavior which is NOT built into the SDK. The UnprocessedItems collection contains items that were rejected by the service for various reasons and you have to write your own logic to handle those.

Comments

1

After sending Response we can handle unprocessed Item's background Process until all unprocessed Items should be complete. below code is useful for you

var AWS= require('aws-sdk');
var docClient = new AWS.DynamoDB.DocumentClient();
router.post('/someBatchWrites',(req,res)=>{
    docClient.batchWrite(params, function (error, data) {
        res.send(error, data);
        handler(error, data);//handling unprocessed items /back ground
    })
});
    
//handle Method      
function handler(err, data) {
    if (err) {
        console.log("Error", err);
    } else {
        console.log("Success", data);
        if (Object.keys(data.UnprocessedItems).length) {
            setTimeout(() => { docClient.batchWrite({ RequestItems: data.UnprocessedItems }, handler);
            }, 100000);
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.