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);
// ...
});
});
};
推荐答案
消息在完成请求之前退出流程"表示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屋!