Subscription Workflow Tutorial with Amazon SWF and Amazon SNS - Amazon Simple Workflow Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

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) and Amazon Simple Notification Service (Amazon SNS) together to emulate a "human task" workflow—one in which a human worker is required to perform some action and then communicate with Amazon SWF to launch the next activity in the workflow.

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 to access Amazon SWF and Amazon SNS, but there are many development options available, including the Amazon Flow Framework for Ruby, which provides easier coordination and communication with Amazon SWF.


This tutorial uses version 1 of the Amazon SDK for Ruby. The SDK for Ruby continues to work, but we recommend that you use the Amazon Flow Framework for Java as an alternative.

For a complete list of Amazon SWF development options, see Development Options.

About the Workflow

The workflow that we will be developing consists of four major steps:

  1. Get a subscription address (email or SMS) from the user.

  2. Create an SNS topic and subscribe the provided endpoints to the topic.

  3. Wait for the user to confirm the subscription.

  4. 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.


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 what development options you are using.

Tutorial Steps

This tutorial is divided into the following steps: