AWS Flow Framework: Can we run activity worker and activity task on different EC2 instances

811 views Asked by At

I am newbie to AWS and want to use Simple workflow service. So far I know is

URL: http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/awsflow-basics-application-structure.html

1) Workflow starter, workflow worker (decider) and activities worker can run on same EC2 instance or each one can run on different EC2 instance.

2) Activities worker execute activity tasks or activity methods

My question is:

1) Can I run Workflow starter, workflow worker (decider), Activities worker on one EC2 instance and Activity tasks or activity methods on different EC2 instance?

Example:

EC2 instance 1 -> Workflow starter, workflow worker(decider), Activities worker

EC2 instance 2 -> Activity tasks or activity methods

If above thing is possible then can anyone point me to some example?

I have looked at AWS Helloworld distributed application but it runs Workflow worker and Activities worker on different EC2 instance where activity task run on same machine as Activities worker URL: http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/getting-started-example-helloworldworkflowdistributed.html

Requirement At beginning only one instance of EC2 would be running:

1) On this running EC2 instance, I will have Workflow starter and workflow worker (decider).

2) Based on task received in decision task list, decider will execute custom logic and based on custom logic outcome I want to create an new instance of EC2 and execute activity worker on it.

Issue is I read somewhere that workflow worker (decider) and activity worker must be started before receiving a task in decision task list and in my case I cannot keep running 2 EC2 instances from the beginning because of cost reason.

Hence to solve this issue my solution was

1) Start decider and activity worker on the running instance of EC2.

2) Once the activity worker receives the task in activity task list, it will create a new instance of EC2 and execute the activity on it.

Thanks

1

There are 1 answers

2
Mircea On

yes. you can definitely do this. you can also have multiple workers (both workflow and activities) on multiple machines. you should not really care where the workflow and activities run as long as the work is getting done.

here is a sample I wrote to show how to use flow with java 1.8

https://github.com/mirceal/swf-flow-java18-sample

In App.java, comment line 42 (aw.start()) and build sample. After that comment line 43 (wfw.start()) and build sample. Copy the 2 built samples to 2 different machines and you should achieve what you are asking for. line 51 starts the workflow.

Edit

Think of the workers as entities that have the ability to perform a task. The workers constantly look at a SWF (poll SWF) and if there is work they pick it up and execute it.

There is nothing preventing you from running workflow and activity workers on the same machine. There is also nothing preventing you from spinning up EC2 instances from an activity.
If you need to only run part of activities on a machine and other activities on other machines (the ones you spin up) you would typically use different SWF task lists.