Running Activities

If you need to run only a single activity at a time, you don't need to write any workflow code—you can use the start method to automatically create a workflow and start a workflow execution to run your activity.

Note

The start method can run only one activity per workflow execution. If your workflow consists of more than one activity, create decider methods of your own. For more information, see Implementing Workflows.

To run an activity

  1. Write an activity method that takes one parameter, the activity input. The activity method must reside within a class. For example:

    class HelloWorld
      def hello(input)
        "Hello #{input[:name]}!"
      end
    end
    
  2. Call the start method, providing it with the activity's name (a combination of its class name and method name, joined by a period) and a block of optional input data to pass to the activity. For example, to run the hello activity method and provide it with input:

    require 'aws/decider'
    AWS::Flow::start("HelloWorld.hello", { name: "AWS Flow Framework!" })
    

The start method will register your activity if necessary, create and register a workflow to run it, and will start a workflow execution.

If you do not provide any activity options to start, it will use the following defaults:

Option Value
version "1.0"
data_converter YAMLDataConverter
exponential_retry { maximum_attempts: 3 }
start_to_close_timeout "NONE"
schedule_to_close_timeout "NONE"
schedule_to_start_timeout "NONE"
heartbeat_timeout "NONE"
task_list "USE_WORKER_TASK_LIST"

You can modify any of these activity options by passing them as a block after the input data when you call start:

require 'aws/decider'
AWS::Flow::start("HelloWorld.hello", { name: "AWS Flow Framework!" }) {
  {
    heartbeat_timeout: 10,
    task_priority: 500,
  }
}

For More Information#

Use the following topics and resources to learn more about running activities:

On this page: