GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - pragonauts/lambda-wrap

BranchesTags
Open more actions menu

Latest commit

 

History

29 Commits
29 Commits

Folders and files

NameName
Last commit message
Last commit date
.circleci
.circleci
 
 
bin
bin
 
 
lib
lib
 
 
test
test
 
 
.eslintrc
.eslintrc
 
 
.gitignore
.gitignore
 
 
.istanbul.yml
.istanbul.yml
 
 
.nvmrc
.nvmrc
 
 
README.md
README.md
 
 
index.d.ts
index.d.ts
 
 
index.js
index.js
 
 
jsconfig.json
jsconfig.json
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 

Repository files navigation

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 } = require('lambda-wrap');

const wrap = lambdaWrap({
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Credentials': 'true',
    },
    callbackWaitsForEmptyEventLoop: false, // usefull for mongodb
    verboseError: true // include error stack in response (possible to )
    verboseLog: true // include headers and body in error log
});

wrap.before((event) => {
    if (event.body && `${event.headers['content-type']}`.match(/^application\/json/)) {
        event.body = JSON.parse(event.body);
    }
});

// or you can set custom logger
wrap.logger = console;

wrap.finally((error, response) => {
    // close connections or send logs
});

module.exports.myHandler = wrap(async (event) => {

    // return json body
    return {
        body: {
            objectAttribute: true
        }
    };
})

API

Classes

lambdaWrap

Functions

error(message, code)

Return new error object.

lambdaWrap

Kind: global class

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.

About

No description, website, or topics provided.

Resources

Readme
Activity
Custom properties

Stars

1 star

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.