statebox
Orchestrate Node functions using Amazon States Language
Useful links
Install
$ npm install statebox --save
Usage
const Statebox = require('statebox')
const statebox = new Statebox()
statebox.createModuleResources(
{
add: class Add {
run (event, context) {
context.sendTaskSuccess(event.number1 + event.number2)
}
},
subtract: class Subtract {
init (resourceConfig, env, callback) {
callback(null)
}
run (event, context) {
context.sendTaskSuccess(event.number1 - event.number2)
}
}
}
)
const info = statebox.createStateMachines(
{
'calculator': {
Comment: 'A simple calculator',
StartAt: 'OperatorChoice',
States: {
OperatorChoice: {
Type: 'Choice',
Choices: [
{
Variable: '$.operator',
StringEquals: '+',
Next: 'Add'
},
{
Variable: '$.operator',
StringEquals: '-',
Next: 'Subtract'
}
]
},
Add: {
Type: 'Task',
InputPath: '$.numbers',
Resource: 'module:add',
ResultPath : '$.result',
End: true
},
Subtract: {
Type: 'Task',
InputPath: '$.numbers',
Resource: 'module:subtract',
ResultPath : '$.result',
End: true
}
}
}
},
{},
function (err) {
}
)
executionDescription = await statebox.startExecution(
{
numbers: {
number1: 3,
number2: 2
},
operator: '-'
},
'calculator',
{}
)
executionDescription = await statebox.describeExecution(
'01e1e288-9533-11e7-8fec-54d168e2e610'
)
Testing
$ npm test
License
MIT