"When using Amazon SWF, you implement workers to perform tasks. These workers can run either on cloud infrastructure, such as Amazon Elastic Compute Cloud (Amazon EC2), or on your own premises. You can create tasks that are long-running, or that may fail, time out, or require restarts—or that may complete with varying throughput and latency. Amazon SWF stores tasks and assigns them to workers when they are ready, tracks their progress, and maintains their state, including details on their completion. To coordinate tasks, you write a program that gets the latest state of each task from Amazon SWF and uses it to initiate subsequent tasks. Amazon SWF maintains an application's execution state durably so that the application is resilient to failures in individual components. With Amazon SWF, you can implement, deploy, scale, and modify these application components independently."
"What is SWF not?
- SWF does not execute any code.
- SWF does not contain the logic of the workflow.
- SWF does not allow you to draw a workflow or a state machine
How does it work?
SWF is based on polling. Your code runs on your machines on AWS or on-premises – it doesn’t matter. Your code is polling for tasks from the SWF API (where they wait in queues), receives a task, executes it, and sends the result back to the SWF API.
SWF then issues new tasks to your code, and keeps the history of the workflow (state)."
SWF then issues new tasks to your code, and keeps the history of the workflow (state)."
neyric/aws-swf-toolkit: A Node.js Framework for workflows on Amazon SWF
AWS Step Functions
"Build distributed applications using visual workflows
AWS Step Functions
"Build distributed applications using visual workflows
{
"Comment": "A Hello World example of the Amazon States Language using a Pass state",
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Pass",
"Result": "Hello World!",
"End": true
}
}
}
ASL: Amazon States Language - AWS Step Functions
{ "Comment": "An example of the Amazon States Language using a choice state.", "StartAt": "FirstState", "States": { "FirstState": { "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:123456789012:function:FUNCTION_NAME", "Next": "ChoiceState" }, "ChoiceState": { "Type" : "Choice", "Choices": [ { "Variable": "$.foo", "NumericEquals": 1, "Next": "FirstMatchState" }, { "Variable": "$.foo", "NumericEquals": 2, "Next": "SecondMatchState" } ], "Default": "DefaultState" }, "FirstMatchState": { "Type" : "Task", "Resource": "arn:aws:lambda:us-east-1:123456789012:function:OnFirstMatch", "Next": "NextState" }, "SecondMatchState": { "Type" : "Task", "Resource": "arn:aws:lambda:us-east-1:123456789012:function:OnSecondMatch", "Next": "NextState" }, "DefaultState": { "Type": "Fail", "Error": "DefaultStateError", "Cause": "No Matches!" }, "NextState": { "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:123456789012:function:FUNCTION_NAME", "End": true } } }
State Types:
- Common State Fields
- Pass: passes input to output
- Task: single unit of work; main building block for state machines; properties
- "Type": "Task",
- "Resource": "arn:aws:lambda:..."
- "TimeoutSeconds": 300, // optional
- "HearthbeatSeconds": 60 // optional
- "Next": "NextState1"
- "Retry": [ { "ErrorEquals": ["CustomError"]. "IntervalSeconds": 1, "MaxAttempts": 5 }]
- "Catch": [ { ... }
- Choice: conditional branching logic ("if statement", "switch", create loops)
- { "Choices": [ { "Variable": "$.foo", "NumericEquals": 1, "Next", "MatchOne" } ...
- "And": [...], "Not": [...], "Or": [...]
- Wait: delay execution
- "Seconds": 10 ==> wait 10 seconds before next state
- "Timestamp": "2020-01-01T00:00:00Z" // wait until specified time
- "SecondsPath": "$.waitseconds" // use input variable
- "TimestampPath": "$.expirydate" // use input var
- Succeed: end state
- "SuccessState": { Type": "Succeed" }
- Fail: end state
- "FailState": { "Type": "Fail", "Cause": "Data error", "Error": "inventory low" }
- Parallel: parallel execution
- "StateP1": { "Type": "Parallel", "Next": "FinalState",
"Branches" : [ { "StartAt": "Wait 20s", " States: { "Wait 20s" { ... } } },
using "path" to filter portion of input for processing and output; example
{ "numbers": [2, 3], "sum": 5 }
{ "Type": "Task", "Resource": "arn:aws:lambda:us-east1:123:function:Add", "Next", "NextStep",
"InputPath": "$.numbers", "ResultPath": "$.sum", "OutputPath": "$.sum" }
State Machine Data - AWS Step Functions
"You can now use a local version of AWS Step Functions to develop and test your workflows."
No comments:
Post a Comment