Middy

The stylish Node.js middleware engine for AWS Lambda proudly sponsored by fourTheorem and AWS.

Simplify Node.js Lambda function code.

Middy empowers you to incorporate common elements like authentication, authorisation, validation, and serialisation in a modular and reusable fashion. By decoupling these concerns from your primary code, Middy allows you to keep your attention squarely on your business logic, resulting in cleaner and more efficient serverless applications.

Make your code more maintainable and easier to test.

Middy helps you to modularise and streamline your AWS Lambda functions

Benefits

Simple but Powerful

Middleware engines organise your code, eliminate duplication, and standardise handling of authentication, authorisation, validation, & serialisation.

Exceptional Speed

Keep your lambda as fast as possible. Middy’s minimal core keeps your Lambda size small and your cold starts under control. Add only what you need!

Productivity

By pushing all the non-functional code to middlewares, you can be productive and focus on what matters the most: the business logic!

Extensibility

Need something custom? Creating your own middlewares is incredibly simple. And, if that’s not enough, you can even extend middy itself through its hooks.

Batteries Included

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.

Lean and Efficient

Middy comes with a very small core and an unobtrusive API to add the minimum amount of overhead to your code.

Middy is supported in Powertools for AWS Lambda (TypeScript)

Powertools is a developer toolkit for implementing Serverless best practices and boosting developer velocity. It currently offers the following utilities compatible with Middy

Logger

Structured logging made easier with a middleware to capture key fields from the Lambda context, cold starts, and more. Compatible with Amazon CloudWatch, Datadog, and more.

Tracer 

An opinionated wrapper around AWS X-Ray SDK for Node.js with a middleware to automatically capture traces for function invocations, HTTP requests, and AWS SDK calls, and more.

Metrics 

Create Amazon CloudWatch custom metrics asynchronously with a middleware that takes care of capturing cold starts, and flushes metrics to CloudWatch in EMF-formatted batches.

Idempotency 

Middleware to make your Lambda functions idempotent and prevent duplicate execution based on payload content.

Parser 

Data validation and parsing using Zod, a TypeScript-first schema declaration and validation library.

Middy makes writing Lambda functions easier.

Discover how Middy.js works with JavaScript and TypeScript, how to perform validation, event parsing and parameter loading, and how to write and use your own Middy middleware.