以下是我的问题陈述 -
1. 我有一个区域 API 网关端点
Lambda 调用 VPC 私有子网中的 Lambda 函数来访问 RDS。
对 API Gateway 的 Postman 调用能够调用 Lambda 函数。
Lambda 函数能够正确处理其中的所有内容。
Lambda 函数代码到达代码的响应块,但无法返回响应。
Lambda 函数的安全组允许通过公有子网中的 NAT 网关进行所有出站。
以下是函数处理程序 -
var async = require('async');
var moment = require('moment');
var service = require('./some-service');
exports.handler = (event, context, callback) => {
var requestBody = event['body-json'];
async.waterfall([
function(callback) {
var processRequest = {};
processRequest.validationMessage = validateRequest(requestBody);
if(processRequest.validationMessage == ''){
processRequest.isValid = true;
service.processService(requestBody,function(err, response) {
if(err){
callback(err, null);
}
else{
callback(null, response);
}
});
}
else{
processRequest.isValid = false;
callback(null, processRequest);
}
}
],
function(err, resp) {
let response = {};
if (err) {
response = {
statusCode: 500,
body: JSON.stringify('API Error : ' + err),
};
callback(err, response);
}
else {
if(resp.isValid){
response = {
statusCode: 200,
body: 'Record updated for user_id '+requestBody.user_id,
};
console.log('Success block! ', response);
callback(null, response);
}
else{
console.log('Failure block!');
response = {
statusCode: 500,
body: resp.validationMessage,
};
callback(null, response);
}
}
});
};
function validateRequest(requestBody){
var isValid = '';
if(requestBody['user_id'] == undefined){
console.log('user_id missing');
isValid += 'user_id, ';
}
if(requestBody['added_by'] == undefined){
isValid += 'added_by, ';
}
if(isValid != ''){
isValid = isValid.substring(0, isValid.lastIndexOf(','));
isValid += ' missing in the request';
}
return isValid;
}
CloudWatch 日志显示代码能够到达成功块,
Success block! { statusCode: 200, body: 'Record updated for user_id 17' }
邮递员回应——
{
"message": "Endpoint request timed out"
}
可能是什么问题?