Upgrade 3.x -> 4.x
aka "The AWS SDK v3 Update"
Version 4.x of Middy no longer supports Node.js versions 14.x. You are highly encouraged to move to Node.js 18.x.
Notable changes
- Middy now uses AWS SDK v3 by default.
Core
- Remove polyfill for
AbortControler
- Remove polyfill for
timers/promises
Util
normalizeResponse
now will set thestatusCode
to200
when casting to a new object or500
when missing Breaking Change
Middleware
cloudwatch-metrics
No change
do-not-wait-for-empty-event-loop
No change
error-logger
No change
event-normalizer
No change
http-content-encoding
- Removed body as stream support, will be brought back as a new middleware in a future middleware Breaking Change
http-content-negotiation
No change
http-cors
No change
http-error-handler
No change
http-event-normalizer
No change
http-header-normalizer
No change
http-json-body-parser
- Deprecate
event.rawBody
Breaking Change
You can add in an inline middleware as a workaround.
.before((request) => {
request.event.rawBody = request.event.body
})
.use(httpJSONBodyParserMiddleware())
See https://github.com/middyjs/middy/issues/945 for discussion and reasoning.
http-multipart-body-parser
- Add new option to set
charset
http-partial-response
No change
http-response-serializer
No change
http-router
No change
http-security-headers
No change
http-urlencode-body-parser
- Now throws 422 when unable to parse JSON Breaking Change
http-urlencode-path-parser
No change
input-output-logger
No change
rds-signer
- Updated to use AWS SDK v3 Breaking Change
s3-object-response
- Updated to use AWS SDK v3 Breaking Change
secrets-manager
- Updated to use AWS SDK v3 Breaking Change
service-discovery
- Updated to use AWS SDK v3 Breaking Change
sqs-partial-batch-failure
No change
ssm
- Updated to use AWS SDK v3 Breaking Change
sts
- Updated to use AWS SDK v3 Breaking Change
validator
We've put a lot of work into making this middleware bundle smaller and faster by default, while allowing for opting into more functionality.
- Deprecate
inputSchema
andoutputSchema
options Breaking Change - Deprecated
i18nEnabled
Breaking Change - Must now pass in
defaultLanguage
localizations tolanguages
Breaking Change - Added in
ajv-error
support - Pulled
transpileSchema
out of middleware to allow for tree shaking and pre-compile option Breaking Change - Added in
transpileLocale
to allow for custom internationalization of error messages includingerrorMessage
How to update use of middleware
import validatorMiddleware from '@middy/validator'
// 1. Import transpileSchema
import { transpileSchema } from '@middy/validator/transpile'
export const handler = middy(...)
.use(validatorMiddleware({
// 2. Wrap schemas with transpileSchema
eventSchema: transpileSchema(eventJsonSchema)
}))
import validatorMiddleware from '@middy/validator'
// 1. Import localizations
import { en, fr } from 'ajv-ftl-i18n'
export const handler = middy(...)
.use(validatorMiddleware({
eventSchema: transpileSchema(eventJsonSchema),
// 2. Add localizations in
langauges: { en, fr }
}))
warmup
No change
ws-json-body-parser
No change
ws-response
- Updated to use AWS SDK v3 Breaking Change
ws-router
No change
Notes
None