Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
lambda-request-handler
Advanced tools
An npm module that allows your Node.js web applications to be deployed as an AWS Lambda function and invoked in response to API Gateway, HTTP API, or Application Load Balancer requests.
An npm module that allows your Node.js web applications to be deployed as an AWS Lambda function and invoked in response to API Gateway, HTTP API, or Application Load Balancer requests.
The list of supported frameworks matches in-process-request
nodejs12.x
runtime)Inspired by aws-serverless-express
It supports nodejs10.x
and nodejs12.x
execution environments.
The main differences between this module and aws-serverless-express
are
The handler supports events from the following sources:
There's a demo app showcasing the features of this library available here
The default export of lambda-request-handler
is a function that takes an application handler (i.e. Express.js app instance) as an argument and returns an AWS Lambda handler function.
An additional header is injected into the request
x-aws-lambda-request-id
- AWS Lambda Request Id$ npm install lambda-request-handler
const express = require('express')
const lambdaRequestHandler = require('lambda-request-handler')
const app = express()
app.get('/user/:id', (req, res) => {
res.json({
id: req.params.id,
lambdaRequestId: req.header('x-aws-lambda-request-id')
name: 'John'
})
})
const handler = lambdaRequestHandler(app)
module.exports = { handler }
If the above file in your Lambda source was called index.js
then the name of the handler in the Lambda configuration is index.handler
Sometimes the application needs to read configuration from remote source before it can start processing requests. For example it may need to decrypt some secrets managed by KMS. For this use case a special helper deferred
has been provided. It takes a factory function which returns a Promise that resolves to the app instance. The factory function will be called only once.
const lambdaRequestHandler = require('lambda-request-handler')
const AWS = require('aws-sdk')
const express = require('express')
const createApp = (secret) => {
const app = express();
app.get('/secret', (req, res) => {
res.json({
secret: secret,
})
})
}
const myAppPromise = async () => {
const kms = new AWS.KMS()
const data = await kms.decrypt({
CiphertextBlob: Buffer.from(process.env.ENCRYPTED_SECRET, 'base64')
}).promise()
const secret = data.Plaintext.toString('ascii')
return createApp(secret);
};
const handler = lambdaRequestHandler.deferred(myAppPromise);
module.exports = { handler }
Please note that Hapi v19 dropped support for Node v10. The only AWS Lambda runtime that supports it is nodejs12.x
.
const Hapi = require('@hapi/hapi')
const lambdaRequestHandler = require('lambda-request-handler')
// create custom listener for Hapi
const myListener = new lambdaRequestHandler.HapiListener()
// Pass the custom listener to Hapi.server
const server = Hapi.server({
listener: myListener
});
server.route({
method: 'GET',
path: '/',
handler: (_request: any, _h: any) => {
return 'Hello World!';
}
});
const myAppPromise = async () => {
//wait for the server to initialize
await server.start()
// return the request listener function
return myListener.handler
};
const handler = lambdaRequestHandler.deferred(myAppPromise);
module.exports = { handler }
If the above file in your Lambda source was called index.js
then the name of the handler in the Lambda configuration is index.handler
FAQs
An npm module that allows your Node.js web applications to be deployed as an AWS Lambda function and invoked in response to API Gateway, HTTP API, or Application Load Balancer requests.
The npm package lambda-request-handler receives a total of 43 weekly downloads. As such, lambda-request-handler popularity was classified as not popular.
We found that lambda-request-handler 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.