I have the following code that uses the AWS SDK for Node to hit DynamoDB:
var aws = require('./aws')
...
var key = "fookey";
aws.dynamo.getItem({
"TableName": "TableFoo",
"Key": {
"FooKey": {
"S": key
}
}
}, function(error, data) {
if(err != null) {
callback(500);
}
else if(data.Item != null) {
var obj = { values: [] };
callback(null, obj);
}
else {
callback(null, data.Item.values.S);
}
});
What's happening is that the call successfully executes and the expected result is returned. BUT - then - the callback function is executed a second time and the error object is set to:
{ [SyntaxError: Unexpected token o] statusCode: 200, retryable: false }
Any idea why this is happening? This is with the latest version of the AWS SDK for Node.
TIA.
Interestingly it looks like this happens when you are calling this code from a unit test and an assert in that test fails. I'm going to speak with Amazon about this.
I think you misspelled the error variable at the first if conditional expression. You wrote err instead of error.
function(error, data) {
if(err != null) { <-- // err should be error
callback(500);
}