I'm using the AWS JavaScript SDK to work with DynamoDB.
I wrote the following (simplified) function to get the tables in my DB -
var AWS = require('aws-sdk');
var db = new AWS.DynamoDB();
function getTables() {
db.listTables(function(err, data) {
console.log(data);
return data;
});
}
I can't understand why when I do the following -
x = getTables();
x doesn't get initialized with data (stays undefined
), but console.log(data)
prints the actual result.
I realize it's a callback, but I successfully print the response! It's not like I'm trying to print it outside the function, which would result in me trying to print something that hasn't been initialized yet. The response I get initialized the data
variable, meaning it should be both printed and then returned!
What am I missing here? Thanks in advance