JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 689
  • Score
    100M100P100Q97422F
  • License MIT

Library that makes it easier to invoke lambda functions with promises.

Package Exports

  • aws-lambda-invoke

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aws-lambda-invoke) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

aws-lambda-invoke

Library that makes it easier to invoke lambda functions with promises.

Installation

npm install --save aws-lambda-invoke

Usage

Load the library and pass in the AWS library.

var AWS = require('aws-sdk'),
    lambda = require('aws-lambda-invoke')(AWS);

Why am I not embedding the aws-sdk in the library? This is because in AWS Lambda, the aws-sdk is globally available for you to use. By not embedding the aws-sdk library, you can keep the footprint of the lambda build smaller.

Sychronous

The invoke method calls the lambda function synchronously. This means that it will wait untill the called lambda function returns a result or fails.

// Invoke the function
lambda.invoke('MyLambdaFunction', {hello: 'world'})
    .then(function(result) {
        // Do something with the result of MyLambdaFunction
    })
    .catch(function(err) {
        // Something went wrong
    });

Asynchronous

If you don't have to wait for the response of the lambda function you can use the invokeAsync method.

// Invoke the function
lambda.invokeAsync('MyLambdaFunction', {hello: 'world'})
    .then(function() {
        // The MyLambdaFunction is invoked successfully
    })
    .catch(function(err) {
        // Something went wrong while invoke MyLambdaFunction
    });

Raw Lambda

If you want to do something with the lambda object created in the aws-lambda-invoke library, you can because the lambda function is stored in the raw property of the library.

var params = {
    FunctionName: 'MyLambdaFunction',
    InvocationType: 'RequestResponse',
    Payload: JSON.stringify({hello: 'world'})
};

lambda.raw.invoke(params, function(err, result) {
    if(err) {
        // Something went wrong    
    }
    else {
        // Do something with the result of MyLambdaFunction
    }
});

Contributors

License

MIT © Sam Verschueren