Dear Team,
We are trying to use AWS lambda as Reverse proxy for Grafana and using node JS for lambda.
Below is the lambda code:
const express = require('express');
const app = express();
const serverless = require('serverless-http');
const port = 8000;
const varenv = 'production';
app.use(express.static('view'))
var http = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({});
proxy.on('proxyReq', function (proxyReq, req) {
proxyReq.setHeader('X-WEBAUTH-USER', 'admin')
});
proxy.on('proxyRes', function (proxyRes, req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
});
proxy.on('error', function (err, req, res) {
res.writeHead(500, {'Content-Type': 'text/plain'});
console.log("error----",err);
console.log("req----",req);
console.log("res----",res);
res.end("An error occured ....Susanta-101");
});
app.all("/*", function (req, res) {
console.log("Forwarding to grafana server...")
proxy.web(req, res, {
target: 'http://stack-Grafa-1GNU1ALCSQL27-734749157.us-east-1.elb.amazonaws.com/', // link to our target service
secure: false
});
// res.end("An error occured...susanta!!!");
})
// process.env.ENVIRONMENT === 'production'
if (varenv === 'production') {
console.log("serverless block...!!!")
exports.handler = serverless(app);
} else {
app.listen(port,
() => console.log(`Susanta Listening on port ${port}!`))
}
Also, connected the lambda to AWS api gateway and accessing through api url and getting the below errors:
Could you please help me out to resolve this one.
Thanks,
Susanta