Getting Empty File with AWS Lambda and ALB

62
October 20, 2021, at 02:40 AM

I have used the Npm package, http-proxy-middleware.

I have pointed a URL to ALB, which is pointing to the mentioned Lambda function.

I am creating this as a reverse proxy to get the binary files from the target URL. But the ALB returns an empty file.

Invoking: the-url-to-alb.com/filename.bin

Steps tried :

  1. The code works on my local machine.
  2. Supposedly for ALB to return binary data it needs to be encoded in base64 format. I tried that, but it doesn't work.

Any insights on this or alternatives would be appreciated.

The code :

const serverless = require('serverless-http');
const app = require('express')();
const { createProxyMiddleware } = require('http-proxy-middleware');
const awsServerlessExpress = require('aws-serverless-express');

app.get("/check", (req,res) => {
        res.send("working now")
    })

app.all('*', (req, res, next) => {
    createProxyMiddleware({ 
        target: 'https://target-url-here.com', changeOrigin: true,
        logLevel: 'debug',
    
        onError: (err, req, res, target) => {
              res.writeHead(500, {
                'Content-Type': 'text/plain',
              });
              res.end('Something went wrong. And we are reporting a custom error message.');
            },
        onProxyReq: (proxyReq, req, res)=> {
              proxyReq.setHeader('Content-Type', 'application/octet-stream');
              proxyReq.setHeader('isBase64Encoded', 'true');
              proxyReq = proxyReq.toString('base64');          
            },
        onProxyRes: (proxyRes, req, res)=> {
            console.log(proxyRes.res);
            console.log("#################################################################################################")
            }
    })(req, res, next);
});
const server = awsServerlessExpress.createServer(app);
//}
//module.exports.handler = serverless(app);
exports.handler = (event, context) => {
    console.log(JSON.stringify(event));
    awsServerlessExpress.proxy(server, event, context)
    
}
READ ALSO
Trying to multiply and make another row in Pandas Dataframe

Trying to multiply and make another row in Pandas Dataframe

How do I make another row called 'Sum'), which contains the sum of for each order line (quantity, multiplied by price)in Pandas

71
Append method to add text to body not working [duplicate]

Append method to add text to body not working [duplicate]

This is such a simple command and I am loading jQuery beforehandOther jQuery on the page is working as well

73
Add <a> href to img with appendto

Add <a> href to img with appendto

I'm hoping someone can help

68
How to use database in Heroku

How to use database in Heroku

I am new in web applications and I created first application in djangoI decided to deployment my project in Heroku

24