Registry / aws / aws-lambda-middleware

aws-lambda-middleware

JSON →
library1.1.2jsnpmunverified

AWS Lambda Middleware is a lightweight library (v1.1.2, last updated 2023) for applying middleware and validating request parameters in AWS Lambda functions. It provides PropTypes for type checking and data correction, a Validate function for custom rules, and supports Express and other frameworks. Key differentiators include minimal overhead for Lambda, deep array/object validation, and customizable error message templates. Release cadence is sporadic, with major changes between v0.9 and v1.0 including reserved prop names, option changes, and required() method replacing isRequired.

awsweb-framework
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CommonJS destructuring only; no default export.

const { Middleware } = require('aws-lambda-middleware')

Prop is an alias for PropTypes; both work.

const { Prop } = require('aws-lambda-middleware')

isRequired deprecated in v1.0; use .required() method.

Prop.string.required()

Creates a Lambda handler with parameter validation using PropTypes and middleware chaining.

const { Middleware, Prop } = require('aws-lambda-middleware') exports.handler = new Middleware().add({ queryStringParameters: { username: Prop.string.required(), age: Prop.integer, friends: [ { name: Prop.string.length({ max: 20 }), gender: Prop.string.or(['male', 'female']) } ] } }).add(async (event, context, prevData) => { const query = event.queryStringParameters console.log(`Hello ${query.username}`) return { statusCode: 200, body: JSON.stringify({ message: 'success' }) } })
Debug
Known footguns
breakingv1.0 changes: object and array are reserved prop names, .required() replaces .isRequired, default() uses named parameters, and option() for trim settings.
breakingv0.9 -> v1.0: interpretation of object and array expressions changed from 'validate only when value exists' to 'required validation'.
deprecated.isRequired is deprecated since v1.0.0.
gotchaProp.string.default('') returns undefined if string is empty; fixed in v1.0.4.
gotchaProp.bool.default(false) sets undefined; fixed in v1.0.4.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources