0

I have an internal API that provides data in different formats by just passing the id + format. For Example if I want to get a PDF of a produc with ID = 1 I will just make a call to the app with apiurl/latest/1.pdf.

This works fine when I am in the internal network since the host is only available internally. To access it publicly, we have implemented an authorization using API gateway and Lambda. Lambda takes are of the authorization and return the result just fine :

  • When I request JSON data
  • When I request XML data Here a sample version of the lambda:

    var request = require('request');

exports.handler = function(event, context, callback) {

  var fUrl = event.fUrl + event.pid;
  if(event.fsUrl.indexOf('product') >-1){
    fUrl = fUrl + '.' + event.format 
  } 
  request({
    url: fUrl,
  }, function(error, response, body) {
      if(error){
        return callback(error);
      }else{
            return callback(null, response.body);
      }
  });

}

but not PDF. Some screens from the postman. I used both Send and Download in Postman.

enter image description here

Any thoughts?

johnny
  • 2,032
  • 1
  • 25
  • 45
  • 1
    Does this Question/Answer help? https://stackoverflow.com/a/45368224/6427978 – Matt D Oct 18 '18 at 13:16
  • I was there but not much. I might take another look. – johnny Oct 18 '18 at 13:18
  • Yeah you're need to give a but more Lambda code for us to help here, I reckon it's the encoding - check this out https://stackoverflow.com/questions/22171510/how-to-download-pdf-using-nodejs-and-send-it-to-the-client/36169684 - Remember when searching Lambda is NodeJS or whatever runtime you're using it's no different at all :-) – Mrk Fldig Oct 18 '18 at 18:14
  • @MrkFldig I updated the questions with lambda snip. – johnny Oct 18 '18 at 18:55
  • Yeah that's not gonna give a proper download to a client unless it has the headers and the correct format from the link above. – Mrk Fldig Oct 18 '18 at 18:57

0 Answers0