Upgrade 2.x -> 3.x
aka "The onError Reversal Update"
Version 3.x of Middy no longer supports Node.js versions 12.x. You are highly encouraged to move to Node.js 16.x. With the Node.js version change all packages are now ECMAScript Modules along side CommonJS Modules.
Notable changes
- New WebSocket middlewares
- HTTP & WebSocket Routers!
- Better error handling
- Timeout error handling
- Errors now use
{ cause }
for better context
Core
onError
middleware stack order reversed to matchafter
[Breaking Change]- If you only use
@middy/*
middlewares no change should be required - This change has trickle down effects on middlewares with
onError
(see below for details) - If you're handling errors yourself here are some things to review:
- Attach near the end so it is triggered first (likely already done)
- Remove
return response
, this will short circuit the response and block later middleware from modifying the response
- If you only use
- lambdaHandler now passes
{signal}
fromAbortController
to allow for ending lambda early to handle timeout errors plugin
argument now supports:internal
: Allow the use ofnew Proxy()
for smarter triggering in advanced use cases.timeoutEarlyInMillis
: When before lambda timeout to trigger early exit. Default5
timeoutEarlyResponse
: Function to throw a custom error or return a pre-set value. Default() => { throw new Error('Timeout') }
- Added
.handler()
method to allow easier understanding of the execution cycle - Deprecate
applyMiddleware()
and__middlewares
[Breaking Change]