emulator
emulator copied to clipboard
Getting ERR_EMPTY_RESPONSE with sls run, working fine with invoke (local or not)
Hi
I was excitant to file this as an issue, then I filed it in the forum, but TBH it feels more like an issue.
I have a lambda that returns a JSON based on an API response, which may contain an array with over than 2000 items.
Basically, if you sls run --watch
then open http://localhost:400/hello, it works fine. But if you change this for(let i = 0; i < 2000; i++) {
to loop anything over 2200 it fails, the browser gets ERR_EMPTY_RESPONSE
. The interesting part is that, it only fails on sls run
it works fine with sls invoke
(local or not)
Any ideas on what it could be?
service: hello
provider:
name: aws
runtime: nodejs6.10
functions:
hello:
handler: hello.handler
events:
- http:
path: hello
method: get
cors: true
export const handler = async (event, context, callback) => {
let items = []
// 2000 works
// 2200 fails ERR_EMPTY_RESPONSE
for(let i = 0; i < 2000; i++) {
items.push({ "id": i })
}
const data = { "items_size": items.length, "items": items }
callback(null, { statusCode: '200',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true
}
})
}