Reputation: 347
I've deployed a Lambda function, which should get list of items with a scan(params, cb)
function. In console, I see something different, not the returned list, but something that lookgs like http request body or response?
Can you please explain how to get the list correctly and what do I get?
exports.handler = async (event, context, callback) => {
console.log('function started')
let params = {
TableName: "documents"
}
console.log('params get')
let respond = await db.scan(params, (err, data) => {
console.log('scan started')
if (err) console.log(err, err.stack);
else {
console.log('else started')
return data
}
})
console.log('Respons IS: ')
console.log(respond)
};
The response is a huge huge huge list of something:
Upvotes: 0
Views: 65
Reputation: 4656
You are mixing callbacks and async/await ES6 feature.
I advise you to only use the latter in this case.
Here is what it would look like :
const aws = require('aws-sdk');
const db = new aws.DynamoDB.DocumentClient();
exports.handler = async (event, context) => {
console.log('function started');
const params = {
TableName: "documents"
};
console.log('params get');
const respond = await db.scan(params).promise();
console.log('Respons IS: ');
console.log(respond);
return ...
};
Upvotes: 1