【发布时间】:2021-08-30 11:36:09
【问题描述】:
您好,AWS Lambda 向 VPCE 服务器发送查询字符串时遇到问题。我的代码如下:
AWS LAMBDA 代码
exports.handler = function(event, context, callback) {
if (event.queryStringParameters !== null) { // check for query string
console.log('query Strings: ' + querystring.stringify(event.queryStringParameters))
queries = queries + '?' + querystring.stringify(event.queryStringParameters);
}
options = {
hostname: invokeHostname, // 1234567a.execute-api.ap-something-1.amazonaws.com
port: 443,
path: queries, // /api/test/get_something?getId=123
method: event.httpMethod,
headers: {}
};
const req = https.request(options, (res) => {
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => {
console.log("chunk: " + chunk)
rawData += chunk;
});
res.on('end', () => {
console.log('response' + rawData);
response = {
"statusCode": res.statusCode,
"body": rawData,
"isBase64Encoded": false
};
console.log(response);
callback(null, response);
});
});
}
我正在为我的 API 使用 .NET 5 运行 ASP.NET Core,这是我的控制器代码:
控制器 ASP.NET
[ApiController]
[Route("api/[controller]")]
public class TestController : Controller
{
[HttpGet("get_something")]
public IActionResult Test([FromQuery] int getId)
{
// do something here.
}
}
请注意,它确实通过了控制器,但它没有返回任何内容,因为没有设置查询字符串。
但是当在 VPCE 服务器中时,我检查了它接受的日志:https://10.10.3.221/api/test/get_something 仅没有查询字符串 getId=123。有人对此有解决方案吗?
【问题讨论】:
-
您是否检查了 CLoudWatch 日志中的函数错误?
-
我做了,它收到了正确的查询字符串
标签: javascript amazon-web-services aws-lambda .net-5 amazon-vpc