I'm trying to read a basic DynamoDB table in AWS Lambda, following the AWS tutorials. I've got some basic code, that seems to be running OK (I'm not seeing any errors logged), but I can't get any output:
const AWS = require('aws-sdk');
AWS.config.update({region: 'eu-west-1'});
const ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
function readData(){
console.log("In the readData() function");
var params = {
TableName: "desks",
Key: {
"desk_id": {N:'1'}
}
};
console.log("Set params");
// Call DynamoDB to read the item from the table
ddb.getItem(params, function(err, data) {
console.log("In getItem callback function");
if (err) {
console.log("Error", err);
}
else {
console.log("Success", data.Item);
}
});
console.log("Completed call");
}
When my function above is called, the logs show the output "Set params" and "Completed call", but it's like the callback function doesn't get executed. Am I missing something around the execution flow?
Edit: I'm using Node.js 8.10 and I believe I've set up the appropriate role permissions (full access on the database).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…