Middy.js wraps AWS Lambda handlers with composable middleware for validation, auth, logging, error mapping, and AWS event sources. It ships dozens of official packages for API Gateway, queues, streams, and more.
Overview
Middy is a middleware engine tailored to Node.js functions on AWS Lambda. You keep a slim handler for domain logic and chain middleware steps that handle parsing, security headers, CORS, secrets loading, structured errors, and partial-batch failures for streaming event sources.
The core stays small and ESM-first, depending mainly on shared utilities rather than bundling the AWS SDK. TypeScript types ship with the packages, and the maintainers target current Node.js releases. Official middleware covers API Gateway HTTP and REST, WebSockets, Function URLs, SQS, SNS, S3, DynamoDB streams, EventBridge, Kinesis, Kafka, and CloudFormation custom resources, plus routers that dispatch within one function.
Documentation positions Middy for production handlers where repeated non-functional code would otherwise be copied into every file: input validation at trust boundaries, consistent HTTP error shapes, cached secrets prefetch, auth for public endpoints, and graceful timeout responses. Teams can author custom middleware or extend lifecycle hooks when built-ins are not enough.
Lambda response streaming and durable function workflows receive first-class support in recent releases. The project is MIT-licensed, documents integration with AWS Lambda Powertools concepts, and is installed via npm scoped packages such as the core engine and individual middleware modules.
Key features
- Composable Lambda handler middleware chains
- Official packages for major AWS triggers
- HTTP, WebSocket, and CloudFormation routers
- TypeScript types and ESM packaging
- Input validation and error response mapping
- Partial batch failure helpers for queues
- Response streaming and durable function support
- Custom middleware and hook extension points
Use cases
- API Gateway REST or HTTP Lambda APIs
- SQS consumers with partial batch reporting
- Standardizing auth and logging across functions
- WebSocket Lambda connection handlers
- Reducing duplicated Lambda boilerplate