Normalize your serverless functions by abstracting away the differences between the different serverless providers. It adds a standardized request/response model, that you can hook into any framework you like - or use it as is!
The package @serverless-normalize/normalize
automatically identifies which provider you are using and if you have
the compatibility layer installed for that provider, it'll call your function with the Node.js standard
HTTP request and response objects.
- AWS (via
@serverless-normalize/aws
) - serverless-offline
- GCP
- ... accepting PRs for other providers
npm install @serverless-normalize/normalize --save
If you are using AWS or serverless-offline you'll also need the compatibility layer.
npm install @serverless-normalize/aws --save
The callback
has a function signature of:
type Callback = (
request: http.IncomingMessage,
response: http.ServerResponse,
) => void
options
is optional and depends on the provider. Sensible defaults are used for all the providers.
// handler.js
import { normalize } from '@serverless-normalize/normalize';
import Koa from 'koa';
const app = new Koa();
app.use(async ctx => {
ctx.status = 200;
ctx.body = JSON.stringify({ message: 'Yay!' });
});
export default normalize(app.callback());
- Why the relative require?
Two reasons:
There is no support for "optionalPeerDependencies" in apackage.json
file - and we don't want to load more code than necessary.
And the other reason is because of module bundlers (like Webpack) to still be able to do their analysis and not emit errors or warnings about missing packages (which they would have been if you only include the providers you plan on using).
Since scoped packages installs every package under your own scope, this works!
- Alagarr
- serverless-http
- Middy
- corgi
- node-lambda-req
- apigateway-utils
- serverless-utils
- @graphcool/lambda-helpers
Contributions are more than welcome! Just fork and clone the repository and run npm install
.
serverless-normalize © Alexander Liljengård. Released under the MIT license.
Authored and maintained by Alexander Liljengård with help from contributors.