Nonchalantly Perusing Magazines
    Have ideas to improve npm?Join in the discussion! »

    lambda-generator-handler

    1.0.1 • Public • Published

    lambda-generator-handler

    Run a generator function as an AWS Lambda function, when you are using lambda-proxy integration with API Gateway.

    npm version Codeship Status for stevejay/lambda-generator-handler Coverage Status bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies license

    NPM

    Install

    $ npm install --save lambda-generator-handler
    

    Usage

    Create your AWS Lambda function as a generator and then export it wrapped by the lambda-generator-handler package. Note that this library is only for use when you have configured your endpoint in API Gateway to use lambda-proxy integration with your Lambda function.

    const generatorHandler = require('lambda-generator-handler');
     
    function* someHandler(event) {
        // The 'event' arg is the AWS Lambda event object.
        // Throw an error if something bad happens.
        // Return a result as you normally do from a generator.
        return { name: 'the result' };
    }
     
    module.exports.handler = generatorHandler(someHandler);

    If your handler throws an exception, this wrapper catches it and returns an error response to AWS Lambda. It checks that the error message includes a serverless framework type of error code prefix (e.g., the [500] prefix in the message [500] Some error occurred), and adds one if none exists. It also turns a DynamoDB ConditionalCheckFailedException into a 400 Stale Data error response.

    License

    MIT

    Install

    npm i lambda-generator-handler

    DownloadsWeekly Downloads

    4

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • avatar