我有一个kibana示例背后的nodejs 16. x aws lambda反向代理。它的工作几乎一切正常,除了“发现”部分,当我添加2个或更多的过滤器为2个多月的时间范围,它给回坏网关错误。
错误的详细信息:
Wrapper@https://mydomain/_dashboards/909221/bundles/core/core.entry.js:6:4249
_createSuperInternal@https://mydomain/_dashboards/909221/bundles/core/core.entry.js:6:3388
...
...
实施:
function proxy(event, context, lambdaCallback) {
delete(event.headers["accept-encoding"])
var path = event.path;
if (event.multiValueQueryStringParameters) {
path += '?' + deserializeQueryString(event.multiValueQueryStringParameters)
}
// Calculate the options for the HTTPS request
var opts = {
host: my_es_endpoint,
path: path,
method: event.httpMethod,
service: 'es',
region: my_region,
headers: event.headers
}
if ((event.httpMethod == 'POST') || (event.httpMethod == 'PUT')) {
if (event.body) {
var buff = new Buffer(event.body, "base64")
var payload = buff.toString('utf-8')
opts.body = payload
}
}
// Use aws4 to sign the request so we can talk with ElasticSearch directly
aws4.sign(opts);
const req = https.request(opts, function (res) {
var bodyParts = [];
// We need to read all the incoming data
res.on('data', (chunk) => {
bodyParts.push(chunk)
});
res.on("end", () => {
// We re-create the read content
var body = Buffer.concat(bodyParts).toString()
// We send back uncompressed data
delete(res.headers['content-encoding'])
res.headers['X-Frame-Options'] = 'DENY'
// res.headers['content-security-policy'] = "default-src 'self'; frame-ancestors 'none'"
res.headers['X-XSS-Protection'] = '1; mode=block'
res.headers['X-Content-Type-Options'] = 'nosniff'
var response = {
statusCode: res.statusCode,
body: body,
headers: res.headers
}
lambdaCallback(null, response);
})
});
req.on('error', (e) => {
console.log(`Error caught when calling ElasticSearch: ${e}`)
})
// For POST/PUT request, we send the content of the paylod as well
if ((event.httpMethod == 'POST') || (event.httpMethod == 'PUT')) {
if (event.body) {
var buff = new Buffer(event.body, "base64")
var payload = buff.toString('utf-8')
req.write(payload)
}
}
req.end();
return req;
}
我试过:
- 请求时超时增加
- 将lambda内存从128增加到512
- 增加lambda超时
2条答案
按热度按时间zphenhs41#
我认为你可以尝试增加Lambda函数的内存分配,这样可能会解决这个问题。
或者更好,只是消除你所有的头痛.你应该使用亚马逊API网关,而不是反向代理在Lambda函数代理请求Kibana.你也可以增加超时Kibana请求.这将是更有效和可扩展到您的项目和更少的问题.
我试图优化您的代码,您可以检查这是否会改善或纠正您的问题?
6ss1mwsb2#
我不确定错误是否与代理实现有关,但是我发现了一些有帮助的东西,现在我不再遇到这个问题了。
我按照建议减少了Kibana高级设置中
discover:sampleSize
的值here