
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
aws-lambda-middleware
Advanced tools
You can simply apply Middleware in Lambda.Â
Clean code split is possible, and it includes a simple and extensible Parameter PropTypes validater.
It is implemented as lightly as possible to reduce the burden when running Lambda.
🚀 v1.0 added features
A Validate function that is easy to expand and use has been added, and deep data of arrays and objects can now be processed.It is compatible even in environments other than lambda. (node express etc.)
Â
npm i aws-lambda-middleware
Â
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
//your code
return {
statusCode: 200,
body: JSON.stringify({
message: 'success'
})
}
})
Â
You can set global options and cluster options.
You can set options such as
trim.
đź“– Options detail docs
You can simply apply Middleware in Lambda.Â
Checks and corrects the data types of request parameters.
PropTypesandPropare the same object.
It only verifies the validity of the request parameter value.
You can use it by adding custom rules.
đź“– Validate detail docs
Â
The rules added to PropTypes and Validate are written in one line and used.
Error messages can be organized into templates.
đź“– Message detail docs
Â
Introducing a method that can be applied to the Express framework.
It can also be used in other frameworks.
đź“– with Express
 Â
object and array expressionsobject and array are designated as reserved prop name, so the rule cannot be overwritten.
⚠️ Reserved prop names
trim settings for each PropTypes use .option().
{
param: Prop.string.option({ trim: false })
}
PropTypes and PropThe abbreviated Prop can be used instead of the PropTypes.
PropTypes can still be used as well.
.isRequired has been replaced by .required()..isRequired is also compatible, but not recommended.
When dynamically setting the default value of PropTypes, the parameter type has been changed to named parameters.
v0.9
Prop.*.default((event) => {})
v1.0
Prop.*.default(({ event }) => {})
đź“– PropTypes > Support methods
object and array expressionsThe interpretation of Object and Array expressions has been changed from validate only when value exists to required validation.
When setting the body as shown below, the returned status depends, so check the item document in PropTypes > Support methods.
đź“– PropTypes > Support methods
exports.handler = new Middleware().add({
body: {
myId: Prop.string
}
})
v0.9
Even if the body of the request parameter is an empty Object or has no value, status = 200 is returned.
v1.0
If the body of the request parameter is an empty Object or has no value, status = 400 is returned.
In order to validate only when value exists for the body, you must also set PropTypes on the body.
exports.handler = new Middleware().add({
body: Prop.object.item({
myId: Prop.string
})
})
FAQs
AWS Lambda Middleware
The npm package aws-lambda-middleware receives a total of 6 weekly downloads. As such, aws-lambda-middleware popularity was classified as not popular.
We found that aws-lambda-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.