API Gateway (HTTP)
Build APIs with API Gateway v2.
Organise your Lambda code, remove code duplication, focus on business logic. Simple, fast, and extensible.
GitHub Stars
Monthly downloads
Contributors
A middleware engine makes your code more organised, removes duplication and uniforms the handling of non-functional concerns like authentication, authorization, validation, and serialization.
By pushing all the non-functional code to middlewares, you can be productive and focus on what matters the most: the business logic!
Middy comes with a very small core and an unobtrusive API to add the minimum amount of overhead to your code.
Middy comes with a large set of official middlewares and utilities that can be used out of the box to address the most common non-functional use cases.
Middy has been engineered to keep your lambda as fast as possible. The minimal core keeps your lambda size small and your cold starts under control. Add only what you need!
Do you need to do more? It's really easy to write your own custom middlewares. And, if that's not enough, you can even extend middy itself through its hooks.
The following abstract example illustrates the difference of style when using Middy:
export const handler = (event, context) => {
// BOILERPLATE!
// E.g. decrypt environment variables with KMS
// deserialize the content of the event
// validate input, authentication, authorization
// REAL BUSINESS LOGIC
let response = doSomethingUsefulWith(event)
// MORE BOILERPLATE
// E.g.
// validate output
// serialize response
// handle errors
return response
} Without Middy all your non-functional code is mixed up with the actual business logic in your handler.
The code is hard to understand and maintain. What if you need to reuse some of the non-functional logic in another handler?
import middy from '@middy/core'
const lambdaHandler = (event, context) => {
// REAL BUSINESS LOGIC
return doSomethingUsefulWith(event)
}
export const handler = middy(lambdaHandler)
.use(/* Your own behaviour in a reusable fashion */)
.use(/* logging and tracing */)
.use(/* input validation */)
.use(/* authentication */)
.use(/* error handling */)
.use(/* other behaviour */) Middy helps you to keep all the non-functional code outside from your handler function.
The business logic in your handler remains pure and testable. All the non functional logic is isolated and reusable.
See how Middy works across different AWS Lambda trigger types.
Build APIs with API Gateway v2.
Classic REST API integration with API Gateway v1.
Real-time bi-directional communication via WebSockets.
Build APIs with API Gateway v2.
Process messages from SQS queues reliably.
Transform S3 Object responses with Lambda.
Action DynamoDB events.
Process notifications from SNS with ease.
Install Middy in seconds and start building cleaner Lambda functions today.
Read the docsMiddy is open-source and supported by amazing sponsors.