I'm wrapping my dynamoDB function into another function and I'm having issues with returning it to the "item" const. What I'm missing here?
Works:
const params = {
TableName: table,
Key: {
id: id
},
};
dynamoDb.get(params, (error, result) => {
if (error) {
console.error(error);
callback(null, {
statusCode: error.statusCode || 501,
body: 'Couldn\'t fetch the item.',
});
return;
}
const item = result.Item
})
Doesn't work (returns undefinied):
const getFromDb = () => {
const params = {
TableName: table,
Key: {
id: id
},
};
dynamoDb.get(params, (error, result) => {
if (error) {
console.error(error);
callback(null, {
statusCode: error.statusCode || 501,
body: 'Couldn\'t fetch the item.',
});
return;
}
return result.Item
})
}
// Get from db
const item = getFromDb()
// do stuff with result item...