Code Monkey home page Code Monkey logo

aws-lambda-invoke's Introduction

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

aws-lambda-invoke's People

Contributors

samverschueren avatar simonjang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.