https://github.com/includable/serverless-middleware
Default serverless middleware for some of our projects.
https://github.com/includable/serverless-middleware
aws-lambda nodejs serverless
Last synced: 6 months ago
JSON representation
Default serverless middleware for some of our projects.
- Host: GitHub
- URL: https://github.com/includable/serverless-middleware
- Owner: includable
- Created: 2021-06-18T12:30:39.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-14T23:09:22.000Z (about 1 year ago)
- Last Synced: 2025-09-30T05:46:58.474Z (6 months ago)
- Topics: aws-lambda, nodejs, serverless
- Language: JavaScript
- Homepage: https://flexible.agency
- Size: 986 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Serverless Middleware
A helper for writing APIs using AWS Lambda functions.
### Features
- Dependency injection for easy unit testing.
- Pretty JSON error output, with status codes automatically determined based on error message.
- Easy access to query strings and JSON body properties.
- Serverless warmup plugin support.
- OpenTelemetry support and additional span attributes, for use with [opentelemetry-lambda](https://github.com/open-telemetry/opentelemetry-lambda).
---
## Installation
```shell
yarn add @includable/serverless-middleware
```
## Example usage
```js
import { middleware, auth } from "@includable/serverless-middleware";
const dependencies = {
// dependencies for the dependency injector
};
export const app = async (
{ query, path, body },
{ currentUser /* dependences */ },
) => {
// if `auth` is included in the second param of `middleware`, currentUser
// will be an object in the form of `{ id, groups, email, ... }`
// your business logic goes here
return {
success: true,
text: "Hello, world!",
};
};
export const handler = middleware(app, [auth]).register(dependencies);
```
## Options
### Warmup support
Out of the box this middleware setup supports the [serverless-plugin-warmup](https://github.com/FidelLimited/serverless-plugin-warmup)
serverless plugin.
Simply install the serverless plugin, no other changes to your code necessary.
The middleware will automatically prevent code execution on warmup requests.
### OpenTelemetry span enrichment
If an active OpenTelemetry span is detected, event and response properties will automatically be added.
---
Get professional support for this package →
Custom consulting sessions availabe for implementation support and feature development.