
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.
hapi-lambda
Advanced tools
This module will allow you to host your Hapijs (17+) application on Amazon Lambda with node 8.10+. If you are using API Gateway, you should set the Gateway to "proxy" mode.
CAUTION: There are significant breaking changes between this version and the pre-1.0 versions of this module.
// api.js
const Hapi = require('@hapi/hapi');
module.exports = {
init: async () => {
const server = new Hapi.server({
port: process.env.port || 3000,
routes: { cors: true }
});
const plugins = []; // your plugins here
await server.register(plugins);
// return the server for Lambda support
return server;
},
};
Your index.js file that you expose to Lambda should look like the following:
// index.js
const api = require('./api');
const { transformRequest, transformResponse } = require('hapi-lambda');
// cache the server for better peformance
let server;
exports.handler = async event => {
if (!server) {
server = await api.init();
}
const request = transformRequest(event);
// handle cors here if needed
request.headers['Access-Control-Allow-Origin'] = '*';
request.headers['Access-Control-Allow-Credentials'] = true;
const response = await server.inject(request);
return transformResponse(response);
};
Deployment is a much larger topic and not covered by this module, however I highly recommend deploying your Lambda application with Serverless
Here is an example serverless configuration.
service: hapi-lambda-demo
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-1
functions:
api:
handler: index.handler
events:
- http:
path: "{proxy+}"
method: any
cors: true
plugins:
- serverless-offline
A working repository and example is provided at https://www.carbonatethis.com/hosting-a-serverless-hapi-17-api-with-aws-lambda/
FAQs
Support Hapi 17+ applications on Amazon Lambda
We found that hapi-lambda 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.