AWS Flow Framework Recipes

Sample Code & Libraries>AWS Flow Framework Recipes
Community Contributed Software

  • Amazon Web Services provides links to these packages as a convenience for our customers, but software not authored by an "@AWS" account has not been reviewed or screened by AWS.
  • Please review this software to ensure it meets your needs before using it.

The recipes in this download demonstrate common programming patterns for Amazon Simple Workflow Service using the AWS Flow Framework.


Submitted By: Carl@AWS
AWS Products Used: AWS Flow Framework, Amazon Simple Workflow Service
Language(s): Java
Created On: November 14, 2012 11:45 PM GMT
Last Updated: November 15, 2012 12:18 AM GMT
AWS Flow Framework Recipes

AWS Flow Framework Recipes

Amazon Simple Workflow Service (SWF) helps developers automatically coordinate work in applications for better scalability and performance. To execute work scalably and with low latency, developers typically spawn multiple processes that can execute across multiple machines. They must then write custom code to distribute work, manage execution state, define how the application reacts to failed or delayed processes, and manage work streams that can complete at different times. This custom work-coordination code adds complexity for developers who want to focus on implementing what an application does, not how the application's work gets done. To help developers automate work coordination in their applications, SWF provides a programming model for developers to express work coordination business logic, as well as a service to manage the coordination of work itself.

To adopt SWF, a developer needs to add "decider" code to a new or existing application that defines work coordination logic by specifying work sequencing, timing, and failure conditions. The developer also implements "activities", which are application components that execute each step of the work. The decider and activities form a "workflow." Once you have the decider and activities in place, the SWF service coordinates the work on behalf of the application. You can use any programming language to develop against the SWF API. We also provide a Java client, AWS Flow Framework, which provides built-in support for things like retry logic for failed or delayed work.

The recipes in this download show a set of commonly used programming patterns that you can use in your application's decider logic to tell SWF how to coordinate your application's work. The recipes are implemented in Java and use the AWS Flow Framework. Each recipe consists of a workflow implementation that demonstrates how to address a common use case, such as how to execute multiple tasks concurrently and merge the results. The recipes are accompanied by JUnit tests that run the workflows. The download also includes a PDF file with installation and setup instructions and detailed documentation for each recipe. The download includes the following recipes:

Repeatedly Execute an Activity

  • ForLoopInlineRecipeWorkflowImpl shows how to use a for loop to repeatedly execute an activity a specified number of times.
  • ConditionalLoopActivitiesImpl shows how to use a recursive asynchronous method to repeatedly execute an activity a specified number of times.
  • DoWhileWorkflowImpl shows how to use a recursive asynchronous method to repeatedly executean activity while a condition is satisfied.

Execute Multiple Activities Concurrently

  • RunMultipleActivitiesConcurrentlyWorkflowImpl shows how to run a fixed number of activities concurrently and merge the results.
  • JoinBranchesWorkflowImpl shows how to run a dynamically determined number of activities concurrently and merge the results.
  • PickFirstBranchWorkflowImpl shows how to execute multiple activities concurrently and use the result from the first activity to complete.

Execute Workflow Logic Conditionally

  • ExclusiveChoiceWorkflowImpl shows how to execute one of several activities based on a condition.
  • MultiChoiceWorkflowImpl shows how to execute multiple activities from a larger group, based on a condition.

Complete an Activity Task Manually

  • humanActivity shows how to implement an activity that is manually completed by a person.

Handle Exceptions Thrown by Asynchronous Code

  • CleanupResourceWorkflowImpl shows how to use TryCatchFinally to handle exceptions thrown by asynchronous code such as activities and clean up resources.
  • HandleErrorWorkflowImpl shows how to handle exceptions thrown by asynchronous code by invoking other asynchronous code.

Retry Failed Asynchronous Code

  • RetryActivityRecipeWorkflowImpl shows how to retry an activity by simply retrying the activity until it either completes or the retry attempts reach a specified limit.
  • ExponentialRetryAnnotationActivities shows how to annotate an activity so that the framework retries it automatically by using an exponential retry strategy, which waits for an increasingly long period between each retry, and stops at a specified point.
  • DecoratorRetryWorkflowImpl shows how to implement exponential retry by using the RetryDecorator class, which allows you to specify the retry policy at run time and change it as needed.
  • AsyncExecutorRetryWorkflowImpl shows how to implement exponential retry by using the AsyncRetryingExecutor class, which allows you to specify the retry policy at run time. In addition, you use the AsyncRunnable abstraction to implement a run method, which AsyncRetryingExecutor calls to execute the activity for each retry attempt.
  • CustomLogicRetryWorkflowImpl shows how to implement a custom retry strategy.

Signal a Workflow

  • WaitForSignalWorkflowImpl shows how a workflow can wait a specified time for a signal before proceeding.

For more details about how to use Amazon SWF and the AWS Flow Framework, see:

What is AWS Flow Framework (Java)?

Amazon Simple Workflow Service

About this Library

  • Based on the 2012-01-25 SWF API version
  • Requires the AWS SDK for Java
  • Version: 1.0
  • Release date: 11/14/2012

Before you begin

Installation and set up instructions are in the PDF file that is included with the download package.

©2017, Amazon Web Services, Inc. or its affiliates. All rights reserved.