-1

I have a function on AWS Lambda the purpose of which is to fetch a .zip from a REST API, extract its contents, and then display its contents with another viewer app. I'm using expressjs for routing, and I'm using the request module to handle the requests.

My app.js looks similar to this:

app.get('/', function(req, res) {

    var r = request(queryURL); // Where queryURL is a get request to fetch a .zip file

    r.on('response', function(response) {
        response.pipe(fs.createWriteStream('/tmp/testFile.zip'))
            .on('close', function() {
                res.send('Test message');
        })
    })
})

module.exports = app;

The problem seems to be with response.pipe(fs.createWriteStream(...)); I can fetch an unrelated html and pipe that into /tmp/testFile.html and render it with res.sendFile('/tmp/testFile.html') just fine. I can even fetch individual images from the same API. But something about the .zip files breaks things.

This all works when run locally, but when I upload it to lambda it breaks, rendering {"message": "Internal server error"} on the browser. I have no idea how to access logs - I upload my function using ClaudiaJS.

Here is my handler function, in case that might be relevant:

'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)

Thanks!

2 Answers2

0

Finally figured out how to access the cloudwatch logs and realized that Lambda was timing out. I changed the timeout from 3 seconds to 30 seconds and it has worked fine since.

0

I was having issues using the native https for pipe. After i saw you answer, I tried out using Axios + https://stackoverflow.com/a/47217305/4922074 and it worked!