Try Amazon Simple Workflow Service (SWF) with Python and boto3

Source to try

https://github.com/rysk92/aws-swf-boto3/

try

cp config.json.sample config.json

Write the name of each swf item in. AWS_PROFILE describes the one that has access to SWF.

{
  "swf": {
    "DOMAIN": "test-domain",
    "WORKFLOW": "test-workflow",
    "TASKNAME": "test-taskname",
    "VERSION": "0.1",
    "TASKLIST": "test-tasklist"
  },
  "aws": {
    "profile": "AWS_PROFILE"
  }
}

Create Domain / Workflow Type / Activity Type

Create

python testcreate.py

Domain confirmation

aws swf describe-domain --name test-domain --profile AWS_PROFILE
{
    "domainInfo": {
        "status": "REGISTERED", 
        "name": "test-domain", 
        "description": "Test SWF domain"
    }, 
    "configuration": {
        "workflowExecutionRetentionPeriodInDays": "10"
    }
}

Workflow Type confirmation

List

aws swf list-workflow-types --domain "test-domain" --registration-status REGISTERED --profile=AWS_PROFILE
{
    "typeInfos": [
        {
            "status": "REGISTERED", 
            "creationDate": 1472616047.186, 
            "workflowType": {
                "version": "0.1", 
                "name": "test-workflow"
            }, 
            "description": "Test workflow"
        }
    ]
}

Describe

aws swf describe-workflow-type --domain "test-domain" --workflow-type "name=test-workflow,version=0.1" --profile=AWS_PROFILE
{
    "configuration": {
        "defaultTaskStartToCloseTimeout": "NONE", 
        "defaultExecutionStartToCloseTimeout": "250", 
        "defaultTaskList": {
            "name": "test-tasklist"
        }, 
        "defaultChildPolicy": "TERMINATE"
    }, 
    "typeInfo": {
        "status": "REGISTERED", 
        "creationDate": 1472616047.186, 
        "workflowType": {
            "version": "0.1", 
            "name": "test-workflow"
        }, 
        "description": "Test workflow"
    }
}

Activity Type confirmation

List

aws swf list-activity-types --domain test-domain --registration-status REGISTERED --profile AWS_PROFILE  
{
    "typeInfos": [
        {
            "status": "REGISTERED", 
            "creationDate": 1472616047.336, 
            "activityType": {
                "version": "0.1", 
                "name": "test-taskname"
            }, 
            "description": "Test worker"
        }
    ]
}

Describe

aws swf describe-activity-type --domain "test-domain" --activity-type "name=test-taskname,version=0.1" --profile=AWS_PROFILE

{
    "configuration": {
        "defaultTaskStartToCloseTimeout": "NONE", 
        "defaultTaskList": {
            "name": "test-tasklist"
        }
    }, 
    "typeInfo": {
        "status": "REGISTERED", 
        "creationDate": 1472616047.336, 
        "activityType": {
            "version": "0.1", 
            "name": "test-taskname"
        }, 
        "description": "Test worker"
    }
}

Start Decider

python testdecider.py
Listening for Decision Tasks
Poll timed out, no new task.  Repoll

Start a worker

python testworker.py   
Listening for Worker Tasks
Poll timed out, no new task.  Repoll

Create a WorkFlow

Create a Workflow by specifying the Domain, workflowId, workflowType name and version, and taskList name.

Create

python testrequest.py 
Workflow requested:  {u'runId': u'abcdefghijklmnopqrstuvwxyz1234567890abcdefghij', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx', 'HTTPHeaders': {'x-amzn-requestid': 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx', 'content-length': '58', 'content-type': 'application/x-amz-json-1.0'}}}

Verification

aws swf list-open-workflow-executions --domain "test-domain" --start-time-filter "oldestDate=1475593200,latestDate=1475679600" --profile=AWS_PROFILE
{
    "executionInfos": [
        {
            "startTimestamp": 1475654057.8, 
            "execution": {
                "workflowId": "test-1001", 
                "runId": "u'abcdefghijklmnopqrstuvwxyz1234567890abcdefghij"
            }, 
            "executionStatus": "OPEN", 
            "cancelRequested": false, 
            "workflowType": {
                "version": "0.1", 
                "name": "test-workflow"
            }
        }
    ]
}

Check the reaction of Decider

python testdecider.py
Listening for Decision Tasks
Poll timed out, no new task.  Repoll
Dispatching task to worker {u'workflowId': u'test-1001', u'runId': u'u'abcdefghijklmnopqrstuvwxyz1234567890abcdefghij'} {u'version': u'0.1', u'name': u'test-workflow'}
Task Dispatched: 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Task Completed!
Poll timed out, no new task.  Repoll

Check the worker's reaction

python testworker.py   
Listening for Worker Tasks
Poll timed out, no new task.  Repoll
New task arrived
Task Done

View the History of Workflow Execution

aws swf get-workflow-execution-history --domain "test-domain" --execution "workflowId=test-1001,runId=abcdefghijklmnopqrstuvwxyz1234567890abcdefghij" --profile=AWS_PROFILE
{
    "events": [
        {
            "eventId": 1, 
            "eventType": "WorkflowExecutionStarted", 
            "workflowExecutionStartedEventAttributes": {
                "taskList": {
                    "name": "test-tasklist"
                }, 
                "parentInitiatedEventId": 0, 
                "taskStartToCloseTimeout": "NONE", 
                "childPolicy": "TERMINATE", 
                "executionStartToCloseTimeout": "250", 
                "input": "", 
                "workflowType": {
                    "version": "0.1", 
                    "name": "test-workflow"
                }
            }, 
            "eventTimestamp": 1475654722.825
        }, 
        {
            "eventId": 2, 
            "eventType": "DecisionTaskScheduled", 
            "decisionTaskScheduledEventAttributes": {
                "startToCloseTimeout": "NONE", 
                "taskList": {
                    "name": "test-tasklist"
                }
            }, 
            "eventTimestamp": 1475654722.825
        }, 
        {
            "eventId": 3, 
            "eventType": "DecisionTaskStarted", 
            "eventTimestamp": 1475654722.903, 
            "decisionTaskStartedEventAttributes": {
                "scheduledEventId": 2, 
                "identity": "decider-1"
            }
        }, 
        {
            "eventId": 4, 
            "eventType": "DecisionTaskCompleted", 
            "decisionTaskCompletedEventAttributes": {
                "startedEventId": 3, 
                "scheduledEventId": 2
            }, 
            "eventTimestamp": 1475654723.059
        }, 
        {
            "eventId": 5, 
            "eventType": "ActivityTaskScheduled", 
            "activityTaskScheduledEventAttributes": {
                "taskList": {
                    "name": "test-tasklist"
                }, 
                "scheduleToCloseTimeout": "NONE", 
                "activityType": {
                    "version": "0.1", 
                    "name": "test-taskname"
                }, 
                "decisionTaskCompletedEventId": 4, 
                "heartbeatTimeout": "NONE", 
                "activityId": "activityid-yyyyyyy-yyyyyyy-yyyyyyy-yyyyyyy-yyyyyyy", 
                "scheduleToStartTimeout": "NONE", 
                "startToCloseTimeout": "NONE", 
                "input": ""
            }, 
            "eventTimestamp": 1475654723.059
        }, 
        {
            "eventId": 6, 
            "eventType": "ActivityTaskStarted", 
            "eventTimestamp": 1475654723.109, 
            "activityTaskStartedEventAttributes": {
                "scheduledEventId": 5, 
                "identity": "worker-1"
            }
        }, 
        {
            "eventId": 7, 
            "eventType": "ActivityTaskCompleted", 
            "activityTaskCompletedEventAttributes": {
                "startedEventId": 6, 
                "scheduledEventId": 5, 
                "result": "success"
            }, 
            "eventTimestamp": 1475654723.147
        }, 
        {
            "eventId": 8, 
            "eventType": "DecisionTaskScheduled", 
            "decisionTaskScheduledEventAttributes": {
                "startToCloseTimeout": "NONE", 
                "taskList": {
                    "name": "test-tasklist"
                }
            }, 
            "eventTimestamp": 1475654723.147
        }, 
        {
            "eventId": 9, 
            "eventType": "DecisionTaskStarted", 
            "eventTimestamp": 1475654723.19, 
            "decisionTaskStartedEventAttributes": {
                "scheduledEventId": 8, 
                "identity": "decider-1"
            }
        }, 
        {
            "eventId": 10, 
            "eventType": "DecisionTaskCompleted", 
            "decisionTaskCompletedEventAttributes": {
                "startedEventId": 9, 
                "scheduledEventId": 8
            }, 
            "eventTimestamp": 1475654723.241
        }, 
        {
            "eventId": 11, 
            "eventType": "WorkflowExecutionCompleted", 
            "workflowExecutionCompletedEventAttributes": {
                "result": "success", 
                "decisionTaskCompletedEventId": 10
            }, 
            "eventTimestamp": 1475654723.241
        }
    ]
}

Recommended Posts

Try Amazon Simple Workflow Service (SWF) with Python and boto3
Use Amazon Simple Notification Service with Python
Try running Google Chrome with Python and Selenium
Try scraping with Python.
Try making a simple website with responder and sqlite3
[Cloudian # 8] Try setting the bucket versioning with Python (boto3)
Easily try Amazon EMR / Cloud Dataproc with Python [mrjob]
Install selenium on Mac and try it with python
Try to operate DB with Python and visualize with d3
Let's make a simple game with Python 3 and iPhone
Crawling with Python and Twitter API 1-Simple search function
Programming with Python and Tkinter
Try hitting the Twitter API quickly and easily with Python
Encryption and decryption with Python
Try Python output with Haxe 3.2
S3 operation with python boto3
Try to bring up a subwindow with PyQt5 and Python
Try running Python with Try Jupyter
python with pyenv and venv
Try face recognition with Python
Works with Python and R
I made a simple circuit with Python (AND, OR, NOR, etc.)
[Cloudian # 6] Try deleting the object stored in the bucket with Python (boto3)
[Machine learning] Try running Spark MLlib with Python and make recommendations
Make a simple OMR (mark sheet reader) with Python and OpenCV
Try to display google map and geospatial information authority map with python
Create a simple Python development environment with VS Code and Docker
[Python] Try to recognize characters from images with OpenCV and pyocr
Communicate with FX-5204PS with Python and PyUSB
Shining life with Python and OpenCV
Try scraping with Python + Beautiful Soup
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
Scraping with Python, Selenium and Chromedriver
Try to operate Facebook with Python
Try singular value decomposition with Python
Scraping with Python and Beautiful Soup
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
Reading and writing NetCDF with Python
Try face recognition with python + OpenCV
I played with PyQt5 and Python3
Reading and writing CSV with Python
Try frequency control simulation with Python
Automate simple tasks with Python Part0
Multiple integrals with Python and Sympy
Coexistence of Python2 and 3 with CircleCI (1.0)
Easy modeling with Blender and Python
Sugoroku game and addition game with python
FM modulation and demodulation with Python
Try using Amazon DynamoDB from Python
Introduction and usage of Python bottle ・ Try to set up a simple web server with login function
[Cloudian # 3] Try to create a new object storage bucket with Python (boto3)
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
Try converting latitude / longitude and world coordinates to each other with python
Try to make foldl and foldr with Python: lambda. Also time measurement
[Cloudian # 1] Try to access object storage with AWS SDK for Python (boto3)