
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@zooxsmart/lambda-middleware
Advanced tools
@zooxsmart/lambda-middleware is a simple middleware implementation for AWS Lambda.
It uses async/await for handlers, no "callback hell".
This module also provides some basic middlewares.
const middleware = require('@zooxsmart/lambda-middleware');
const CompanyMapper = require('./CompanyMapper');
const getParams = require('./getParams');
const handler = middleware.pipeline();
handler.use(getParams());
handler.use(middleware.halResponse().halEntity);
handler.handler(async event => {
const mapper = new CompanyMapper();
return mapper.fetch(event.pathParameters.id);
});
module.exports = { handler };
Here we have a get company example using some recommended lambda middlewares embedded in middleware.pipeline(),
decorates the output with HAL links for the entity and a custom middleware getParam() to fetch database parameters.
This module implements the middleware pipeline in a onion style.
The terminology "pipeline" is often used to describe the onion. One way of looking at the "onion" is as a queue, which is first-in-first-out (FIFO) in operation. This means that the first middleware on the queue is executed first, and this invokes the next, and so on (and hence the "next" terminology)
Each middleware receives the event and context, and pass to the handler only when wanting to hand off processing.
A middleware can return a response immediately, for example validate in input before handling it to the handler. In this case, the pipeline will not continue and the request will not even reach the handler.
The pipeline will return the middleware engine.
Options:
{
useRecommended: true
}
You can add other middlewares using the use(middleware) method and finally your handler with the handler(handler) method.
Will set context.callbackWaitsForEmptyEventLoop = wait;
Will wrap the following middlewares and handler with a try/catch and return a formatted json response (recommended using http-errors). If not using http-errors, set expose to true so the message can be used. See http-errors for more details.
Will parse a body string into json and ensure the presence of pathParameters, queryStringParameters, requestContext and requestContext.authorizer.
Will decorate an entity json with the _link.self from HAL and a collection with links, pagination, and it's entities.
The middleware will use context.statusCode for the response with fallback to 200.
Will fetch the keys from SSM Parameter Store, embed in the destination and cache the result for the specified expiryMs.
process.env, contextWill fetch the keys from AWS Secrets Manager, embed in the destination and cache the result for the specified expiryMs.
context . context will be used if nullYou can create a custom middleware and even call another middleware, just follow the following signature and example:
const middleware = require('../lambda-middleware');
module.exports = () => {
return async (event, context, next) => {
if (process.env.NODE_ENV !== 'development') {
const params = {};
await secretManager({ MYSQL: 'prod/mysql' })(event, params, (ev, ctx) => {
process.env.MYSQL_HOST = ctx.MYSQL.host;
process.env.MYSQL_USER = ctx.MYSQL.username;
process.env.MYSQL_PASS = ctx.MYSQL.password;
});
}
return next(event, context);
};
};
const middleware = require('../lambda-middleware');
module.exports = () => {
return async (event, context, next) => {
if (process.env.NODE_ENV !== 'development') {
return middleware.parameterStore(
{
MYSQL_HOST: '/production/MYSQL_HOST',
MYSQL_USER: '/production/MYSQL_USER',
MYSQL_PASS: '/production/MYSQL_PASS',
},
process.env,
)(event, context, next);
}
return next(event, context);
};
};
Warning Don't forget to call return next(event, context) at the end or the pipeline will not continue and will get no response.
FAQs
Simple middleware implementation for AWS Lambda
We found that @zooxsmart/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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.