Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including seneca-aws-lambda with all npm packages installed. Try it out:

require("aws-sdk/package.json"); // aws-sdk is a peer dependency. var senecaAwsLambda = require("seneca-aws-lambda")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

seneca-aws-lambda v1.0.2

Use AWS Lambda

seneca-aws-lambda

npm version Build Status

This plugin invokes AWS Lambda functions.

Install

Install via npm. You will need install Seneca.js also.

npm install seneca-aws-lambda

Setup

var AWS = require('aws-sdk');
AWS.config.update({region: 'us-west-2'});

var seneca = require('seneca')();
seneca.use('aws-lambda');

options

  • instance: (string, default 'new AWS.Lambda()') an instance of AWS Lambda you want to use
var AWS = require()
var seneca = require('seneca')();

// Use a shared key string
seneca.use('aws-lambda', {
    instance: new AWS.Lambda({apiVersion: '2015-03-31'})
});

AWS Configuration

Refer to the AWS SDK for authenticating to AWS prior to using this plugin.

Provided actions

seneca-aws-lambda provide the following actions. (all including the {role: "aws-lambda"})

invoke - run a lambda function

  • arguments: functionName all other arguments are passed to the lambda function
  • result: result of the lambda function
seneca.act({role: 'aws-lambda', cmd: 'invoke', functionName: 'imgr-search', text: 'metalocolypse'}, function (err, results) {
    if (err) {
        return console.log(err);
    }

    console.log(results); // Show the results of the lambda function
});

You even just invoke a lambda function and not wait for the response. However, this still requires your lambda function to still call context.done() so seneca does not time out.

Lambda Function

exports.handler = function(event, context) {
    context.done(); // Call done immediately to alert seneca

    // Do some heavy lifting
};

Invoke with No Callback

seneca.act({role: 'aws-lambda', cmd: 'invoke', functionName: 'no-response', key: 'value'});

Test

npm test

License

MIT © Blain Smith

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free