Deploying Workflows with Elastic Beanstalk

You can use Elastic Beanstalk to deploy and run your AWS Flow Framework for Ruby workflows, activities and workers. This topic will lead you through the procedure to do so, using the example provided in Hello World.

Prerequisites#

This example assumes that you meet the following prerequisites:

  • Ruby and the AWS Flow Framework for Ruby (at least version 2.4.0) are installed as described in Setting Up.
  • Your AWS credentials are configured as described in Providing AWS Credentials.

Create the Workflow Application#

Creating a workflow application that can be deployed and run on Elastic Beanstalk is similar to creating a local application with aws-flow-utils.

To create the application:

  1. Open a command-line window and use aws-flow-utils to create an application skeleton, specifying -c eb to create an Elastic Beanstalk-compatible application. You also need to set the region to run the EC2 instances in, using the -r argument:

    aws-flow-utils -n HelloBeanstalk -c eb -r us-west-2
    
  2. This will create a project in the HelloBeanstalk directory in the path where you ran aws-flow-utils, and will output a 1-Click URL that you can use to create your Elastic Beanstalk application. It will look something like this:

    ---
    Your AWS Flow Framework for Ruby application will be located at:
      /path/to/HelloBeanstalk/
    AWS Elastic Beanstalk 1-Click URL:
      http://console.aws.amazon.com/elasticbeanstalk/?region=...
    ---
    

    Save the generated URL—you will use it to configure your application.

    The project directory will contain the following directories and files:

    HelloBeanstalk
     |-- Gemfile
     |-- config.ru
     |-- flow
     |   |-- activities.rb
     |   `-- workflows.rb
     `-- worker.json
    
  3. In the flow/activities.rb file, add the following code:

    class HelloWorld
      def hello(input)
        "Hello #{input[:name]}!"
      end
    end
    
  4. Create a .zip archive of the HelloBeanstalk directory in a way that is supported by your operating system. On Linux, Unix or OS X systems, you can type:

    zip -r HelloBeanstalk.zip HelloBeanstalk
    

That's all you need in order to create your workflow application. Now you can deploy it with Elastic Beanstalk.

Configure your Application using the Elastic Beanstalk Console#

The 1-Click URL that was printed to the screen as output when you ran aws-flow-utils will be used now to configure your application on the Elastic Beanstalk console so that you can deploy it.

To configure your application on the AWS Elastic Beanstalk console:

  1. Sign in to the AWS Management Console, and follow the 1-Click URL provided in the output of the aws-flow-utils command. The URL will bring you to Elastic Beanstalk's Create New Application page, pre-configured for your application.

    _images/eb_howto-app_info.png
  2. Enter an optional Description and click Next.

  3. On the Environment Type page, choose Web Server for the Environment tier option.

    _images/eb_howto-env_type.png
  4. Ensure that the Predefined Configuration is Ruby, and click Next.

  5. On the Application Version page, choose Upload your own, and click Browse..., choosing the HelloBeanstalk.zip file that you created earlier.

    _images/eb_howto-app_ver.png
  6. Click Next to proceed to the Environment Information page. There are no options that need to be set on this page.

  7. Click Next to proceed to the Additional Resources page. Again, there are no options that need to be set on this page.

  8. Click Next to proceed to the Configuration Details page.

  9. On the Configuration Details page, choose an EC2 key pair, or open a new browser window and configure one now, using the IAM Console.

  10. Choose an Instance Profile that has access to Amazon EC2, Elastic Beanstalk, and Amazon SWF.

  11. Click Next to proceed to the Environment Tags page. You can leave the tags empty.

  12. Click Next to proceed to the Review page.

  13. Review your application's settings, and click Launch to begin creating your deployment.

Elastic Beanstalk will take some time to fully launch your application. When it is ready, you'll see Health of your Elastic Beanstalk deployment turn to a green circle:

_images/eb_howto-deploy_success.png

Your workflow is now deployed!

Start a Workflow Execution#

Lastly, you need to start a workflow execution so that your workers receive tasks to process.

To start a workflow execution:

  1. Open a command-line window and create a local script (call it starter.rb). Add the following code:

    require 'aws/decider'
    AWS::Flow::start("HelloWorld.hello", { name: "AWS Flow Framework!" })
    
  2. Run the script using Ruby:

    ruby starter.rb
    

This will begin executing the hello activity on your Elastic Beanstalk-deployed application.