1.1.1 • Published 6 years ago
@stephenmathieson/sls-utils v1.1.1
@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.