我用两个console.log调用创建了这个简单的函数。日志中显示“创建承诺后”,而“执行扫描承诺”不出现。我是node.js的新手。我的错误在哪里?
exports.handler = async(event, context) => {
var AWS = require("aws-sdk");
AWS.config.update({
region: "us-east-1",
endpoint: "https://dynamodb.us-east-1.amazonaws.com"
});
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: "User",
KeyConditionExpression: null,
FilterExpression: 'CusomerId = :customerid',
};
var scanPromise=docClient.scan(params).promise();
console.log('\r\nAfter promise created');
scanPromise.then(function(err,data)
{
console.log('\r\nScan promise executed');
});
};
答案 0 :(得分:0)
您的handler
是一个异步函数。如果您不返回承诺,处理程序将被执行,但是它将立即退出,而无需等待您的承诺完成。
将其更改为return scanPromise.then(...)