JSPM

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

Invoke AWS Lambda functions with ease

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 Build Status

Invoke AWS Lambda functions with ease

Installation

npm install --save aws-lambda-invoke

Usage

Make sure the aws-sdk is available in the project. The SDK is not shipped with this library because it is globally available in AWS Lambda. By not embedding the SDK, you can keep te footprint of the lambda build is small as possible.

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.

const lambda = require('aws-lambda-invoke');

lambda.invoke('MyLambdaFunction', {hello: 'world'}).then(result => {
    console.log(result);
    //=> '{"foo": "bar"}'
});

Or with an alias

const lambda = require('aws-lambda-invoke');

lambda.invoke('MyLambdaFunction:production', {hello: 'world'}).then(result => {
    console.log(result);
    //=> '{"foo": "baz"}'
});

Asynchronous

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

const lambda = require('aws-lambda-invoke');

lambda.invokeAsync('MyLambdaFunction', {hello: 'world'}).then(() => {
    // invoked successfully
});

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.

const lambda = require('aws-lambda-invoke');

const params = {
    FunctionName: 'MyLambdaFunction',
    Qualifier: 'my-alias',
    InvocationType: 'RequestResponse',
    Payload: JSON.stringify({hello: 'world'})
};

lambda.raw.invoke(params, (err, result) => {
    // handle the result
});

API

invoke(name, [payload])

Returns a promise that resolves the payload returned by the invoked lambda function.

invokeAsync(name, [payload])

Returns a promise that resolves nothing.

name

Required
Type: string

Name of the lambda function you want to invoke. You can append the version or alias to the name separated by a colon.

payload

Type: object string

Payload you want to send to the lambda function you are invoking.

License

MIT © Sam Verschueren