【发布时间】:2018-08-06 18:32:00
【问题描述】:
我正在尝试在 .then() 块中调用 callback(null,response) 。当我使用serverless offline 时它工作正常,但在使用serverless 时它给出错误。
有两种情况:
1 工作正常(使用serverless deploy 部署和使用sls offline start 时)
module.exports.getAssembly = (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!'
}),
};
callback(null, response)
}
2 与sls offline 一起工作正常,但给internal server error 与serverless deploy
module.exports.getAssembly = (event, context, callback) => {
mysql.query('SELECT * from assemblies',connection).then((returnedObject)=>{
const response = {
statusCode: 200,
body: JSON.stringify({
message: returnedObject.results
}),
};
callback(null, response)
})
}
promise 的 .then() 块内的 callback(null,response) 存在一些问题
【问题讨论】:
-
添加 catch 块并检查。
-
在我的机器上,我正在使用 .catch() 块。此外,验证了日志,它只在 .then() 块内。
-
您可以发布通话的 Cloudwatch 日志吗?
-
CloudWatch 日志:START RequestId: xxxx 版本:$LATEST 2018-02-27T06:31:09.623Z xxxx {timeStamp: 2018-02-27T06:31:09.623Z , log:' 请求查询-> SELECT * from assembly '} 2018-02-27T06:31:09.674Z xxxx {timeStamp: 2018-02-27T06:31:09.674Z, log:'查询结果成功'} END RequestId: xxxx REPORT RequestId: xxxx Duration : 6006.15 ms 计费持续时间: 6000 ms 内存大小: 1024 MB 使用的最大内存: 27 MB 2018-02-27T06:31:15.626Z xxxx 任务在 6.01 秒后超时
标签: node.js aws-lambda es6-promise serverless serverless-framework-offline