Subscription Workflow Tutorial with Amazon SWF and Amazon SNS
This section provides a tutorial that describes how to create an Amazon SWF workflow application that consists of a set of four activities that operate sequentially. It also covers:
-
Setting default and execution-time workflow and activity options.
-
Polling Amazon SWF for decision and activity tasks.
-
Passing data between the activities and the workflow with Amazon SWF.
-
Waiting for human tasks and reporting heartbeats to Amazon SWF from an activity task.
-
Using Amazon SNS to create a topic, subscribe a user to it, and publish messages to subscribed endpoints.
You can use Amazon Simple Workflow Service (Amazon SWF)
Because Amazon SWF is a cloud-based web service, communication with Amazon SWF can originate from anywhere a connection to the Internet is available. In this case, we will use Amazon SNS to communicate with the user by either email, an SMS text message, or both.
This tutorial uses the Amazon SDK for Ruby
Note
This tutorial uses the Amazon SDK for Ruby, but we recommend that you use the Amazon Flow Framework for Java.
Topics
- About the Workflow
- Prerequisites
- Tutorial Steps
- Subscription Workflow Tutorial Part 1: Using Amazon SWF with the Amazon SDK for Ruby
- Subscription Workflow Tutorial Part 2: Implementing the Workflow
- Subscription Workflow Tutorial Part 3: Implementing the Activities
- Subscription Workflow Tutorial Part 4: Implementing the Activities Task Poller
- Subscription Workflow Tutorial: Running the Workflow
About the Workflow
The workflow that we will be developing consists of four major steps:
-
Get a subscription address (email or SMS) from the user.
-
Create an SNS topic and subscribe the provided endpoints to the topic.
-
Wait for the user to confirm the subscription.
-
If the user confirms, publish a congratulatory message to the topic.
These steps include activities that are completely automated (steps 2 and 4), and others that require the workflow to wait for a human to provide some data to the activity before the workflow can progress (steps 1 and 3).
Each step relies on data that is generated by the previous step (you must have an endpoint before subscribing it to a topic, and you must have a topic subscription before you can wait for confirmation, etc.) This tutorial will also cover how to provide activity results upon completion, and how to pass input to a task that is being scheduled. Amazon SWF handles coordination and delivery of information between the activities and the workflow, and vice-versa.
We're also using both keyboard input and Amazon SNS to handle communication between Amazon SWF and the human who is providing data to the workflow. In practice, you can use many different techniques to communicate with human users, but Amazon SNS provides a very easy way to use email or text messages to notify the user about events in the workflow.
Prerequisites
To follow along with this tutorial, you will need the following:
If you already have these set up, you're ready to continue. If you don't want to run the example, you can still follow the tutorial—much of the content in this tutorial applies to using Amazon SWF and Amazon SNS regardless of the development option you choose.
Tutorial Steps
This tutorial is divided into the following steps: