{
"StartAt": "Introduction",
"States": {
"Introduction": {
"Type": "Pass",
"Catch": [ {
"ErrorEquals": [ "Not interested" ],
"Next": "Escape"
} ],
"Next": "Presentation"
},
"Escape": {
"Type": "Pass",
"End": true
},
"Presentation": {
"Type": "Pass",
"Next": "Questions ?"
},
"Questions ?": {
"Type" : "Choice",
"Choices": [ {
"Variable": "$.crystalClear",
"BooleanEquals": true,
"Next": "Answer"
} ],
"Default": "Have fun"
},
"Answer": {
"Type": "Pass",
"Next": "Questions ?"
},
"Have fun": {
"Type": "Parallel",
"Next": "Return home and start building awesome stuff",
"Branches": [ {
"StartAt": "Have a beer",
"States": {
"Have a beer": {
"Type": "Pass",
"End": true
}
}
}, {
"StartAt": "Eat some pizza",
"States": {
"Eat some pizza": {
"Type": "Pass",
"End": true
}
}
}, {
"StartAt": "Network",
"States": {
"Network": {
"Type": "Pass",
"End": true
}
}
} ]
},
"Return home and start building awesome stuff": {
"Type": "Pass",
"End": true
}
}
}
Component coordination layer
TL;DR: To do what FaaS can't
use only FaaS
code should be focusing on business logic, not on what should happen after
strong dependency between your functions
suits your exact requirements
could be fun (see Netflix Conductor)
requires time to develop and maintain
don't you have higher priorities?! 🤔
Amazon State Language
https://states-language.net/spec.html
{
"StartAt": "FirstState",
"TimeoutSeconds": 3600,
"States": {
"FirstState": {
"Type": "Pass",
"End": true
}
}
}
{
"Type": "Task",
"Resource": "arn:aws:states:us-east-1:123456789012:activity:HelloWorld",
"Next": "NextState"
}
Works with Lambda and Activity
{
"Type": "Choice",
"Choices": [ {
"Not": {
"Variable": "$.type",
"StringEquals": "Private"
},
"Next": "Public"
} ],
"Default": "DefaultState"
}
{
"Type": "Wait",
"Seconds": 10,
"Next": "NextState"
}
Time/Timestamp fixed or from the input (JSON path)
{
"Type": "Parallel",
"Branches": [ {
"StartAt": "Worker1",
"States": {
"Worker1": {
"Type": "Task",
}
}
}, {
"StartAt": "Worker2",
"States": {
"Worker2": {
"Type": "Task",
}
}
} ]
}
{ // Input
"title": "Numbers to add",
"numbers": { "val1": 3, "val2": 4 }
}
{ // State definition
"InputPath": "$.numbers",
"ResultPath": "$.sum"
}
{ // Output
"title": "Numbers to add",
"numbers": { "val1": 3, "val2": 4 },
"sum": 7
}
{
"Retry": [ {
"ErrorEquals": [ "ErrorA", "ErrorB" ],
"IntervalSeconds": 1,
"BackoffRate": 2,
"MaxAttempts": 2
}, {
"ErrorEquals": [ "ErrorC" ],
"IntervalSeconds": 5
} ],
"Catch": [ {
"ErrorEquals": [ "States.ALL" ],
"Next": "Z"
} ]
}
Was executed once a day on EC2, now divided in 8 lambdas
Stateless
Long to start
Need to wait and loop in the state machine
Stateless
More limited (no EFS access)
Can't be faster
Need a full time running poller
$ serverless invoke stepf --name MyStepFunction --path my-input.json
$ npm install -g asl-validator
$ asl-validator --json-path definition.json
✓ State machine definition is valid
serverless-stepfunction-validator
$ serverless validate
$ npm install -g stepfunctions-local
$ stepfunctions-local start
$ aws stepfunctions --endpoint http://localhost:4584
create-state-machine
--name my-state-machine
--definition '{"Comment":"A Hello World example of the Amazon States Language using a Pass state","StartAt":"HelloWorld","States":{"HelloWorld":{"Type":"Pass","End":true}}}'
--role-arn arn:aws:iam::0123456789:role/service-role/MyRole
$ aws stepfunctions --endpoint http://localhost:4584
start-execution
--state-machine-arn arn:aws:states:local:0123456789:stateMachine:my-state-machine
--name my-execution
--input '{"comment":"I am a great input !"}'
And now officially supported by AWS 👏
tmp
space available from all the executionAdding integration with services: