LambdaWrap
Simple async function wrapper for AWS lambda and serverless library
- allows using common middlewares (before, catch)
- allows to set common error response format
- supports generator functions using
co
(optional)
const lambdaWrap = ; const wrap = ; wrap; // or you can set custom loggerwraplogger = console; wrap; moduleexportsmyHandler =
API
Classes
Functions
- error(message, code)
Return new error object.
lambdaWrap
new lambdaWrap([globalOptions])
lambdaWrap
function. You can pass options to override or assign new
attributes to event
object. For example add custom headers:
const headers = {
'X-Auth-Token': 'my-token'
};
const wrap = lambdaWrap({ headers });
It returns an instance of LambdaWrap
- wrap
object. This object can
be used for specifying additional properties:
wrap.responseHandler = customResponseFunction;
Finally, wrap
object can be used as a function to wrap any generator
function and thus create lambda handler:
const handler = wrap(async (event) => {
return {
body: 'Hello world'
};
});
Returns: function
- - the wrap function
Param | Type | Description |
---|---|---|
[globalOptions] | LambdaWrapOptions |
Use to override or assign new attributes |
error(message, code)
Return new error object.
Kind: global function
Param | Type | Description |
---|---|---|
message | string |
Error message. |
code | integer |
Error code. |