AWS.DynamoDB.DocumentClient.get 总是 returns 空

AWS.DynamoDB.DocumentClient.get always returns null

我想通过 Lambda 函数从 DynamoDB 项目中检索数据。但是,下面的代码总是returns null.

async function getData(userId) {
  let documentClient = new AWS.DynamoDB.DocumentClient();
  let params = {
    TableName: 'mytable',
    Key: {
      user_id: userId
    }
  };
  let result = await documentClient.get(params).promise();
  console.log(result);
  return result;
}

module.exports.handler = async event => {
  let test = getData('test');
  return { statusCode: 200, body: test };
};

我的 DynamoDB table 看起来像 this。

有什么想法吗?

根据评论。

getData 的解决方案是await

module.exports.handler = async event => {
  let test = await getData('test');
  return { statusCode: 200, body: test };
};