AWS Lambda“完成请求前进程退出" [英] AWS Lambda "Process exited before completing request"
问题描述
我正在尝试调用 DynamoDB 客户端方法并从 DynamoDB 表中获取一项.我正在使用 AWS Lambda.但是,我不断收到消息:
I am trying to call a DynamoDB client method and get one item from the DynamoDB table. I am using AWS Lambda. However, I keep getting the message:
完成请求前进程退出."
"Process exited before completing request."
我增加了超时时间只是为了确保,但处理时间小于超时时间.有什么建议吗?
I have increased the timeout just to make sure, but the processing time is less than the timeout. Any advice?
console.log('Loading event');
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
exports.handler = function(event, context) {
dynamodb.listTables(function(err, data) {
});
var params = {
"TableName": "User",
"Key":
{"User Id" : {"S":event.objectId}
},
"AttributesToGet" : ["First Name","Last Name", "Latitude", "Longitude"],
"ConsistentRead" : true
}
dynamodb.getItem(params, function(response,result) {
response.on('data', function(chunk){
console.log(""+chunk);
console.log("test1")
context.done(result);
});
result.on('ready', function(data){
console.log("test2")
console.log("Error:" + data.error);
console.log("ConsumedCapacityUnits:" + data.ConsumedCapacityUnits);
context.done('Error',data);
// ...
});
});
};
推荐答案
消息Process exited before completed request"表示Javascript函数在调用context.done
(或context.succeed
等).通常,这意味着您的代码中存在一些错误.
The message "Process exited before completing request" means that the Javascript function exited before calling context.done
(or context.succeed
, etc.). Usually, this means that there is some error in your code.
我不是 Javascript 专家(根本)所以可能有更优雅的方法来查找错误,但我的方法是在我的代码中放入一堆 console.log
消息,运行它,然后查看日志.我通常可以将违规行归零,如果我看的时间足够长,我通常可以找出我的错误.
I'm not a Javascript expert (at all) so there may be more elegant ways to find the error but my approach has been to put a bunch of console.log
messages in my code, run it, and then look at the logs. I can usually zero in on the offending line and, if I look at it long enough, I can usually figure out my mistake.
我看到你已经有一些日志记录了.您在输出中看到了什么?
I see you have some logging already. What are you seeing in the output?
这篇关于AWS Lambda“完成请求前进程退出"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!