Giter Club home page Giter Club logo

swf-lambda-decider's Introduction

swf-lambda-decider

Amazon Lambda Decider for Amazon Simple WorkFlow (SWF)

Intro

This library tries its best to make it easy to write SWF deciders in Javascript, and host them on Amazon Lambda.

Important: this library does not poll SWF for decision task. To launch decider-lambdas, we recommand using the swf-lambda-decider-poller project.

Usage

New: To simplify the developpement of lambda-deciders, please check out the swf-lambda-decider YeoMan generator

  • Create a new npm package for your workflow decider :
$ mkdir myworkflowdecider
$ cd myworkflowdecider
$ npm init
  • Add dependency to swf-lambda-decider :
$ npm install swf-lambda-decider --save
  • edit your index.js file with your decider code (see example below)

  • zip and upload to Amazon Lambda

Important: Lambda IAM Role MUST be able to call SWF functions (be sure to set policy)

Input of this lambda should be the decisionTask itself

Example

exports.handler = require('swf-lambda-decider')(function (w) {

    w.activity({
      name: 'step1',
      activity: 'sleep'
    })(function(err, results) {

      w.timer({
        name: 'step2',
        delay: 10
      }, { timerId: '12345' })(function(err, data) {

        w.stop({
          result: 'Everything is good !'
        });

      });

    });

});

Note about the aws-sdk dependency

To send the lambda response, we need the aws-sdk version >=2.1.45

At the time this is being written, the version available into lambda is 2.1.35 : http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html

Deployment

We recommand using https://github.com/neyric/swf-lambda-decider-gulp-tasks to automate deployment.

(Which is made automatically available if you use swf-lambda-decider YeoMan generator)

API

Simple Activity

w.activity({
  name: 'step1', // Must be unique
  activity: 'sleep'
})(function(err, results) {
  // ...
});

To specify a custom taskList :

w.activity({
  name: 'step2', // Must be unique
  activity: 'echo',
  taskList: 'my-custom-tasklist'
})(function(err, results) {
  // ...
});

Calling a lambda function

w.lambda({
  "id": "step_0", // Must be unique
  "name": "yql", // Name of the lambda function
  "input": {
    "yqlquery": "SELECT * FROM slideshare.slideshows WHERE user='neyric'",
    "diagnostics": "true",
    "envURL": "http://datatables.org/alltables.env"
  },
  "startToCloseTimeout": "30"
})(function (err, results) {
  // ...
});

swf-lambda-decider's People

Contributors

ericabouaf avatar jwulf avatar

Watchers

SDF avatar James Cloos 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.