Search code examples
javaamazon-web-servicesspring-bootaws-lambdaamazon-swf

How to implement Decider and Activity workers in AWS Flow Framework using AWS Lambda?


We have 2 Spring-boot applications for AWS Flow Framework.

The Decider worker:

@SpringBootApplication
public class WorkerApplication {

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(WorkerApplication.class);
        ApplicationContext context = application.run(args);
        WorkflowWorker workflowWorker = context.getBean(WorkflowWorker.class);

        workflowWorker.start();
    }
}

And Activity worker:

@SpringBootApplication
public class ActivityApplication {

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(ActivityApplication.class);
        ApplicationContext context = application.run(args);
        ActivityWorker activityWorker = context.getBean(ActivityWorker.class);

        activityWorker.start();
    }
}

I'm wondering if it's possible to implement any/both of these using AWS Lambda Service. I understand how to use Lambda's Function Handler:

public interface RequestHandler<I, O> {
    O handleRequest(I var1, Context var2);
}

But I have no idea how to apply it to our SWF since the workers poll for tasks from AWS.

Thanks!

EDIT:

As answered by Maxim Fateev, it is possible to treat lambda tasks as activities, but not for the decider/s.

When I tried it on our SWF under region ap-southeast-1, it was returning an error:

ScheduleLambdaFunctionFailed [with EventId 5] selected
Cause: LAMBDA_SERVICE_NOT_AVAILABLE_IN_REGION
Decision Task Completed Event Id    : 4
Event Timestamp: Mon Oct 03 09:58:05 GMT+800 2016

But when run on region eu-west-1, it completed successfully.

It seems that as of this time, swf to lambda calls, although available, are not yet working properly for some regions (like ap-southeast-1). These are not specified in the current documentation.


Solution

  • SWF Service supports invocation of Lambda functions instead of activities. See Implementing AWS Lambda Tasks section of AWS Flow Framework for Java Programming Guide. Unfortunately there is no way to bind a decider as a Lambda Function yet.