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!