Middy logo

The stylish Node.js middleware engine for AWS Lambda

Organise your Lambda code, remove code duplication, focus on business logic. Simple, fast, and extensible.

Get started

Strong community

  • 3.9k

    GitHub Stars

  • 2M+

    Monthly downloads

  • 200+

    Contributors

Everything you need for clean Lambda code

Show me the code!

The following abstract example illustrates the difference of style when using Middy:

Without 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?

With Middy

  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.

Do you want to see some more realistic examples?

See how Middy works across different AWS Lambda trigger types.

Ready to get started?

Install Middy in seconds and start building cleaner Lambda functions today.

Read the docs

Supported by the community

Middy is open-source and supported by amazing sponsors.