作为@Jonathan的答案,在Integration Request中标记Use Lambda Proxy集成后,在您的源代码中,您应将以下格式实现为通过502 Bad Gateway错误。
NodeJS 8.10:
exports.handler = async (event, context, callback) => {
// TODO: You could get path, parameter, headers, body value from this
const { path, queryStringParameters, headers, body } = event;
const response = {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": JSON.stringify({
path,
query: queryStringParameters,
headers,
body: JSON.parse(body)
}),
"isBase64Encoded": false
};
return response;
};
重新运行API之前,请不要忘记在API Gateway上部署资源。响应JSON仅返回正文中的正确设置。因此,您可以从事件获取路径,参数,标题,正文值
const {path,queryStringParameters,headers,body} =事件;