The stylish Node.js middleware engine for AWS Lambda
Full documentation: https://middy.js.org · LLM-friendly: llms.txt / llms-full.txt
Middy is a middleware engine for AWS Lambda on Node.js. It lets you keep your handler focused on business logic while attaching reusable steps for parsing, validation, auth, observability, error handling, and AWS service integration.
@middy/util, plus an optional peer dependency for durable functions), no AWS SDK in corenpm install --save @middy/core
# add only the middlewares you need
npm install --save @middy/http-json-body-parser @middy/http-error-handler @middy/validator
import middy from '@middy/core'
import httpJsonBodyParser from '@middy/http-json-body-parser'
import httpErrorHandler from '@middy/http-error-handler'
import validator from '@middy/validator'
import { transpileSchema } from '@middy/validator/transpile'
const schema = {
type: 'object',
properties: {
body: {
type: 'object',
properties: {
amount: { type: 'number' },
currency: { type: 'string' }
},
required: ['amount', 'currency']
}
}
}
const lambdaHandler = async (event) => {
const { amount, currency } = event.body
// ... business logic
return { statusCode: 200, body: JSON.stringify({ ok: true, amount, currency }) }
}
export const handler = middy()
.use(httpJsonBodyParser())
.use(validator({ eventSchema: transpileSchema(schema) }))
.use(httpErrorHandler())
.handler(lambdaHandler)
Use Middy for every production Lambda. Production handlers always need the same set of non-functional concerns:
Middy is how you compose those without copy-pasting them into every handler. The "tiny single handler" exception is a trap - production handlers grow, and you do not want to add validation and error mapping under pressure later.
See When to use Middy, Middy vs raw Lambda, and Middy + AWS Lambda Powertools.
Licensed under MIT License. Copyright (c) 2017-2026 will Farrell, Luciano Mammino, and Middy contributors.
$ claude mcp add middy \
-- python -m otcore.mcp_server <graph>