Description
A collection of tools to handle ApiGateway requests and direct function invocation calls on AWS Lambda. Use it as a stand-alone lib in a Lambda function or plugged-in to Apex or any other serverless framework on NodeJS. I'd recommend deploying and managing your Lambda functions with Apex and LambdaReq since they play nicely together.
AWS Lambda Router for NodeJS alternatives and similar modules
Based on the "Web Frameworks" category.
Alternatively, view AWS Lambda Router for NodeJS alternatives based on common mentions on social networks and blogs.
-
Express
Fast, unopinionated, minimalist web framework for node. -
Nest
A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications on top of TypeScript & JavaScript (ES6, ES7, ES8) 🚀 -
Nuxt.js
Nuxt is an intuitive and extendable way to create type-safe, performant and production-grade full-stack web apps and websites with Vue 3. [Moved to: https://github.com/nuxt/nuxt] -
Koa
Expressive middleware for node.js using ES2017 async functions -
fastify
Fast and low overhead web framework, for Node.js -
egg
🥚 Born to build better enterprise frameworks and apps with Node.js & Koa -
verdaccio
📦🔐 A lightweight Node.js private proxy registry -
Feathers
The API and real-time application framework -
AdonisJs Framework
🚀 The Node.js Framework highly focused on developer ergonomics, stability and confidence -
TypeGraphQL
Create GraphQL schema and resolvers with TypeScript, using classes and decorators! -
MERN
⛔️ DEPRECATED - Boilerplate for getting started with MERN stack -
Quick Start
🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈 -
ThinkJS
Use full ES2015+ features to develop Node.js applications, Support TypeScript. -
LoopBack
LoopBack makes it easy to build modern API applications that require complex integrations. -
Moleculer
:rocket: Progressive microservices framework for Node.js -
Derby
MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers -
ActionHero
Actionhero is a realtime multi-transport nodejs API Server with integrated cluster capabilities and delayed tasks -
tinyhttp
🦄 0-legacy, tiny & fast web framework as a replacement of Express -
Lad
Node.js framework made by a former @expressjs TC and @koajs team member. Built for @forwardemail, @spamscanner, @breejs, @cabinjs, and @lassjs. -
Marble.js
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS. -
sqs-consumer
Build Amazon Simple Queue Service (SQS) based applications without the boilerplate -
FoalTS
Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented. -
Trails
:evergreen_tree: Modern Web Application Framework for Node.js. -
lychee.js
:seedling: Next-Gen AI-Assisted Isomorphic Application Engine for Embedded, Console, Mobile, Server and Desktop -
modern-errors
Handle errors in a simple, stable, consistent way -
NestJS REST API boilerplate
NestJS boilerplate. Auth, TypeORM, Postgres, Mailing, I18N, Docker. -
Hemera
🔬 Writing reliable & fault-tolerant microservices in Node.js https://hemerajs.github.io/hemera/ -
Catberry
Catberry is an isomorphic framework for building universal front-end apps using components, Flux architecture and progressive rendering. -
Interfake
:computer: Fake APIs for prototypes & automated tests. -
dawson-cli
A serverless web framework for Node.js on AWS (CloudFormation, CloudFront, API Gateway, Lambda) -
AdonisJs Application
This repo is the pre-configured project structure to be used for creating ambitious web servers using AdonisJs. -
sqs-producer
Simple scaffolding for applications that produce SQS messages -
Perk
A well documented set of tools for building node web applications. -
Restberry
Framework for setting up RESTful JSON APIs with NodeJS. -
Zeronode
Zeronode - minimal building block for NodeJS microservices -
QueryQL
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string! -
express-version-route
A Node.js express middleware that implements API versioning for route controllers -
FortJs
Component based MVC web framework for nodejs targeting good code structures & modularity. -
khalis
Grab Blogger & Google Photos, mp4upload.com,cloudvideo.tv, etc streaming link -
Coher3nTS Project
Cross-platform project template using Electron and Angular with the Phaser game engine. Project has Flexbox integrated for easy and responsive organization of components around the Phaser canvas.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of AWS Lambda Router for NodeJS or a related project?
README
AWS Lambda Router for NodeJS
A collection of tools to handle ApiGateway requests and direct function invocation calls on AWS Lambda. Use it as a stand-alone lib in a Lambda function or plugged-in to Apex or any other serverless framework on NodeJS. I'd recommend deploying and managing your Lambda functions with Apex and LambdaReq since they play nicely together.
Installation
npm install lambda-req --save
Deploy it with Apex
import LambdaReq from 'lambda-req'
const lambda = new LambdaReq()
// set APIGateway handlers
lambda.get('/lreqex_hello', (req, router)=> {
const { params } = req
return { message: 'hello world!', params }
})
lambda.post('/lreqex_hello', (req, router)=> {
const { params } = req
return { message: 'hello world!', params }
})
// set direct invocation handlers
lambda.proxy('hello', (req, router)=> {
const { params } = req
return { message: 'hello world!', params }
})
export default lambda.invoke
Use it stand-alone on Lambda
import LambdaReq from 'lambda-req'
// initialize Lambda with no params, pass them later from handler
const lambda = new LambdaReq()
// set handlers
lambda.get('/v1/test', (req, router)=> {})
lambda.proxy('migrate', (req, router)=> Promise.resolve({}))
// export the handler
// pass the event params on invocation time
export { handler: lambda.invoke }
Invoke other Lambdas
import LambdaReq, { LambdaProxy, LambdaReqError } from 'lambda-req'
const lambda = new LambdaReq()
// set APIGateway handlers
lambda.get('/lreqex_proxy', (req, router)=> {
const { params } = req
const proxy = new LambdaProxy()
// Invoke another Lambda in the same AWS VPC
return proxy.invoke('lreqex_hello', 'hello', params)
.then((response)=> {
return { message: 'Proxy response from lreqex_hello', response }
})
.catch((err)=> {
console.error(err)
throw new LambdaReqError({
message: {
error: {
code: 'lambdaInvocationError',
message: 'lreqex_hello Lambda is unresponsive.'
}
}
})
})
})
export default lambda.invoke
See [more examples](examples/).
API
LambdaReq
This is the Lambda router object. It binds routes and proxies events for a Lambda handler.
.constructor([event = Object
], [context = Object
], [callback = function
])
Pass in the lambda handler event
, context
and callback
on object initialization. However, this is optional since they can be sent diectly on hanlder invocation.
Node 4.3:
const LambdaReq = require('lambda-req').default
function handler (event, context, callback) {
const lambda = new LambdaReq(event, context, callback)
lambda.invoke()
}
module.exports = { handler }
With Babel:
import LambdaReq from 'lambda-req'
function handler (event, context, callback) {
const lambda = new LambdaReq(event, context, callback)
lambda.invoke()
}
export { handler }
.get|.post|.put|.delete|.options(path = String
, handler = function
)
Shorthand methods for binding APIGateway route handlers. ALL APIGateway params (path, query, body) are passed through the params
key on the req
argument. A router instance is passed as the second handler arg. router._event
and router._context
are mapped to the original handler params.
const lambda = new LambdaReq(event, context, callback)
lambda.get('/test', handler)
lambda.post('/test', handler)
lambda.put('/test', handler)
lambda.delete('/test', handler)
lambda.invoke()
async function handler (req, router) {
const { params, headers } = req
return {}
}
A request to https://api-gateway-id.execute-api.eu-west-1.amazonaws.com/prod/test
will fire up the GET
handler on the /test
route.
.proxy(name = String
, handler = function
)
Shorthand method for binding Lambda direct invocation handlers. Used for maintenance tasks (i.e. db migrations, cronjobs) and internal Lambda calls. Each proxy handler has a unique name, passed as a command
key on the Lambda event. A direct call, proxies all the event data to the handler.
const lambda = new LambdaReq(event, context, callback)
lambda.proxy('db_migrate', handler)
lambda.invoke()
async function handler (req, router) {
const { params } = req
return {}
}
Invoke this functions from command line with aws-cli:
#!/usr/bin/env bash
PAYLOAD='{"command":"db_migrate","params":{"name":"users"}}'
aws lambda invoke \
--function-name myFunction \
--payload $PAYLOAD \
out.log
or through aws-sdk:
import AWS from 'aws-sdk'
const config = {
FunctionName: 'myFunction',
Payload: JSON.stringify({ command: 'db_migrate', params: { name: 'users' } })
}
const lambda = new AWS.Lambda()
lambda.invoke(config).promise().then(response => JSON.parse(response.Payload))
.invoke([event = Object
], [context = Object
], [callback = function
])
Invokes the handlers that match the current Lambda route from APIGateway or by a direct invocation call. Optionally, Lambda handler params will be passed along. It's recommended to export this method as a Lambda handler.
import LambdaReq from 'lambda-req'
const lambda = new LambdaReq()
lambda.get('/test', ()=> {})
lambda.proxy('db_migrate', ()=> {})
export { handler: lambda.invoke }
or with Apex
and WebPack
import LambdaReq from 'lambda-req'
const lambda = new LambdaReq()
lambda.get('/test', ()=> {})
lambda.proxy('db_migrate', ()=> {})
export default lambda.invoke
.isApiGateway Bool
It returns true
if the request was an APIGateway invocation. Internally, checks if an HTTP method is set on the Lambda event.
const lambda = new LambdaReq(event, context, callback)
if (lambda.isApiGateway) {
// it's a HTTP call
}
.isProxy Bool
It return true
if the request was a direct Lambda invocation. Internally, checks if a property command
is set on the Lambda event.
const lambda = new LambdaReq(event, context, callback)
if (lambda.isProxy) {
// it's a direct invocation
}
.params Object
Has all the params coming from event.queryStringParameters
, event.pathParameters
and event.body
for an APIGateway call.
Stores all the params coming from event.params
for a direct invocation.
Referenced through req.params
on a handler.
const lambda = new LambdaReq(event, context, callback)
lambda.get('/test', (req)=> {
const { params } = req
// process APIGateway data
})
lambda.proxy('db_migrate', (req)=> {
const { params } = req
// process direct invocation data
})
if (lambda.params) {
// process data
}
.headers Object
Stores the HTTP headers from an APIGateway call.
const lambda = new LambdaReq(event, context, callback)
lambda.get('/test', (req)=> {
const { headers } = req
if (headers['x-auth']) {
// process user authentication
}
})
.currentRoute String
Returns the current invocation route.
LambdaProxy
A wrapper for direct Lambda invocation calls. Sets the command
and parameters
on internal calls.
.constructor([client = Object
= AWS.Lambda
])
.invoke(functionName = String
, command = String
, [params = Object
])
Call a Lambda internally, pass in the command and params.
import { LambdaProxy } from 'lambda-req'
const proxy = new LambdaProxy()
proxy.invoke('myFunction', 'db_migrate', { name: 'users' })
.then((response)=> {
return { message: 'Proxy response from myFunction', response }
})
.catch((err)=> {
console.error('myFunction Lambda is unresponsive', err)
})
LambdaReqError
A tiny wrapper for Lambda request errors.
.constructor({ message, status })
The error has a message and a status that will be passed along to the APIGateway.
lambda.get('/users', (req, router)=> {
const { params } = req
if (!params.id) {
throw new LambdaReqError({
message: {
error: {
code: 'userNotFound',
message: 'User not found.'
}
},
status: 404
})
} else {
const user = await dbConnection.findUser(params.id)
return { user }
}
})
See [more examples](examples/).