I struggle to get my node.js code to function as I want. It is used for an AWS Lambda function.
The code Scan and Output a whole table in a DynamoDB. The issue is I almost never get the console.log("DB SCANNED!") in readdb function outputted in the console ( and no values loaded to "items").
var AWS = require('aws-sdk');
AWS.config.update({region: 'eu-west-1'});
var ddb = new AWS.DynamoDB({apiVersion: '2012-10-08'});
var table = "TABLE";
var paramsRead = {
TableName: table,
};
exports.handler = async (event) => {
await readdb();
console.log("END");
};
function readdb(){
ddb.scan(paramsRead, function(err, data) {
if (err) {
console.log("Error reading DynamoDB", err);
} else {
console.log("DB SCANNED!");
var items = JSON.stringify(data.Items);
let response = {
statusCode: 200,
body: items,
};
}
}
);
}