首先,我写的lambda函数,如:
function jsonResponse(status, header, body) {
return {
headers: Object.assign(header, {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json;charset=utf-8'
}),
statusCode: status,
body: JSON.stringify(body)
}
}
export const hello = async (event, context, cb) => {
const rep = {
message: 'v1.0',
event: event
};
cb(null, jsonResponse(201, {}, rep));
return;
};
它工作确定,但根据无服务器论坛的无服务器办公室论坛和博客的代码应该是
function createResponse(status, header, body) {
return {
headers: Object.assign(header, {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json;charset=utf-8'
}),
statusCode: status,
body: JSON.stringify(body)
}
}
export const hello = async (event, context) => {
const rep = {
message: 'v1.0',
event: event
};
return createResponse(201, {}, rep);
};
对于使用回调参数,因为它不是正式的异步处理程序语法的一部分。
我用的是同一版本的NodeJS 8.10文章,但是当我申请返回功能,我得到502错误:
{
"message": "Internal server error"
}
我的无服务器处理器配置:
functions:
first:
handler: handlers/first.hello
events:
- http:
path: first
method: get
当我尝试在本地运行它,它只是不断没有任何输出,这个处理程序运行。
你能告诉我,为什么它是内部错误,以及如何解决它?