How do I turn off (or increase) timeoutEarlyResponse in Middy?

672 Views Asked by At

Debugging a lambda running locally; using lambda-local and starting the handler up then attaching a Chrome debugger. But halfway through debugging I get this response:

{"error":{"errorMessage":"Timeout","errorType":"Error",
"stackTrace":["Object.timeoutEarlyResponse (/Users/justin.collum/Documents/work/proj0/node_modules/@middy/core/index.cjs:18:15)","/Users/justin.collum/Documents/work/proj0/node_modules/@middy/core/index.cjs:132:35",
"async runRequest (/Users/justin.collum/Documents/work/proj0/node_modules/@middy/core/index.cjs:124:32)"],"level":"error"}}

Based on the stack trace it looks like this error is coming from core Middy, not any of our middlewares.

The middy docs just tell you how to handle timeouts: https://middy.js.org/docs/writing-middlewares/timeouts/

Searching google for "increase middy timeout" doesn't yield any good results, they are all related to the event loop not being empty. I just need to increase the timeout on the handler to something like 30s when I'm running locally but I can't find the setting for that.

1

There are 1 best solutions below

0
On

AWS Lambda passes in context.getRemainingTimeInMillis() which is used inside Middy to determine when it should trigger an early timeout. You can update this to return a longer value or You can set timeoutEarlyInMillis:0 to disable the timeout altogether.