
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.
@dotmh/lambda-controller
Advanced tools
A class to help make lambda function behind AWS API Gateway.
It exposes some common methods to allow you to use Lambda behind API Gateway more as you would making a normal HTTP app.
To install
npm i @dotmh/lamda-controller
Create a new controller
const controller = require('@dotmh/lambda-controller');
class MyController extends controller {}
You then need to declare a method or methods to handle your requests
const controller = require('@dotmh/lambda-controller');
class MyController extends controller {
handler() {
// Your logic goes here
}
}
This will contain your functions logic for that request
Lastly create a function to call the handler on your controller, and export the function as your serverless function
const controller = require('@dotmh/lambda-controller');
class MyController extends controller {
handler() {
// Your logic goes here
}
}
module.exports.handler = (event, ctx, callback) => {
(new MyController(event, ctx, callback)).handler();
}
For API , see Documentation
To keep the library as small as possible it doesn't include some functionality that you may need. This includes request body handling and also functionality like cookies etc. However, the system is designed to be extended. The extention system is based on mixin's these are just normal JS objects that are mixed in to the Lambda controller class.
A mixin that adds a function (method) and getter would look like this
const mixin = {
hello: () => "Hello",
get bye() {
return "Goodbye"
}
}
You can then add the mixin to Lamda controller using the add method.
// ...
(new MyController(event, ctx, callback)).add(mixin).handler();
// ...
Inside your Controller class (the class that extends Lambda Controller) you can use the mixin methods , getters and setters as if they were originally defined on the main Lambda controller class.
const Controller = require('@dotmh/lambda-controller');
class MyController extends Controller {
handler() {
return this.bye;
}
}
You may want to do somethings on intialization of the extending mixin. Normally you would use the constructor for this but because of the way the addon system works, the constructor A) Can not be overridden or extended, and B) would have already have been invoked. For this purpose you can use an "init" function.
To use an init function declare a function called init on your mixin.
const mixin = {
init() {
// ... do something
},
get foo() {
return "bar"
}
}
Your init function wont appear on the Controller after it has been added, but will be called when
the mixin is added to the controller class. It is called in the context of the controller so
this will refer to the controller object.
DotMH has created a number of plugins to add extra functionality to Lambda Controller
Adds Request body handling to Lambda Controller
Adds Cross Origin Resource Sharing support Lambda Controller
For the API documentation see https://dotmh.github.io/lambda-controller
Or to read locally
npm run readdocs
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
Logo design by @dotmh
FAQs
A controller to work on AWS Lambda behind API Gateway
The npm package @dotmh/lambda-controller receives a total of 15 weekly downloads. As such, @dotmh/lambda-controller popularity was classified as not popular.
We found that @dotmh/lambda-controller 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.