Kev*_*ick 3 amazon-dynamodb aws-lambda aws-sdk-nodejs
我正在尝试从我的 DynamoDB 数据库中获取一个项目。我的代码目前的编写方式,我无法从 DynamoDB 检索任何数据。我一定是做错了什么,因为据我从测试中可以看出,我的回调没有被调用。
昨天我花了一整天的时间,自从我今天早上醒来以来一直在修补它,但没有成功。
如果有人能深入了解我在这里做错了什么,我将不胜感激。提前感谢大家!
最后说明:Lambda 函数本身的超时设置为 5 分钟。所以我不认为 Lambda 函数在 db 查询可以返回之前超时。当我运行该函数时,它会在片刻后退出。
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB();
var response = null;
var test = false;
function getFromDB(callback) {
const params = {
TableName: process.env['DB_TABLE_NAME'] // evaluates to 'test-table',
Key: {
"id": {
S: postId // evaluates to a big string, pulling it in from an SNS message. Verified it with console.log(). It stores the expected value.
}
}
};
dynamodb.getItem(params, function(err, data) {
if (err) callback(data, true); // an error occurred
else callback(data, true); // successful response
});
}
getFromDB((data, isCalled) => {
response = data;
test = isCalled;
});
console.log(data); // evaluates to null
console.log(test); // evaluates to false
Run Code Online (Sandbox Code Playgroud)
小智 5
我遇到过类似的问题。我在下面的语句中删除了 async 以解决:
exports.handler = async (event,context)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2505 次 |
| 最近记录: |