Happy Thanksgiving everyone! I am writing a lambda function which calls DynamoDB and I am running into a design/implementation issue.
I have the following code structure:
exports.handler = function(event, context, callback) {
documentClient.batchGet(getParams, function(err, data) {
if (err) {
console.log(err);
} else {
...
while (1) {
documentClient.scan(scanParams, function(err, data)
{
if (err) {
console.log(err);
} else {
...
if (some condition) {
break;
}
}
}
}
}
I can't call break from inside the callback of a documentClient. Also I can't pass variables from inside the documentClient's callback to outside, and then break out of the while loop. I tried creating a variable in the scope of the handler and assigning it a value inside the documentClient callback function, but once the code gets out of scope of the callback, that value is erased and the variable has its original value in the handler scope.
The reason why there is a while loop is because if the table is large scanning will take more than one trial.
Also, another issue is I want to do a callback in the same scope as the handler, not within the nested blocks like the callback function of the scan documentClient. However, I can't seem to pass any data or variable from inside the nested blocks to outside.
I searched and can't find any doc's on this problem. Thanks in advance for reading.