@stephenmathieson/sls-utils
v1.1.1
Published
[![CircleCI](https://circleci.com/gh/stephenmathieson/sls-utils.svg?style=svg&circle-token=4437d0758a24ba185dcf55a7375cc5c5a61fac03)](https://circleci.com/gh/stephenmathieson/sls-utils)
Downloads
6
Readme
@stephenmathieson/sls-utils
Utilities for working with Serverless.
API
utils.Handler(fn)
Create a SLS event handler, abstracting away oddities with responses and async functions.
Example:
const { Handler } = require('@stephenmathieson/sls-utils')
// Create your service.
const fooService = new Handler(async (event, context) => {
const { body: rawBody } = event
const { foo, bar, baz } = JSON.parse(rawBody)
const data = await getData(foo, bar, baz)
return data
})
// Export its handler.
exports.foo = fooService.getHandler()
utils.getHeader(name, headers)
Get the value of the name
header, or null.
Useful because AWS does not normalize (lowercase) headers.
Example:
exports.foo = (event, context, callback) => {
const authorization = getHeader('authorization', event.headers)
if (!authorization) {
// ...
}
}
Releasing
CircleCI will publish all pushed semver-ish tags to npm.