AWS Step Functions II: Integration with DecisionRules - Real-World Use

Expanding on Part I's AWS Step Functions overview, Part II explores practical integration of for dynamic decision-making, enriched by real-time Open Weather API data, showcasing complex workflow orchestration capabilities.

Building on the concepts discussed in Part I, where we introduced AWS Step Functions' role in orchestrating complex workflows and automating decision-making processes, Part II delves into a practical application by integrating for dynamic decision-making, further enhanced by real-time data from the Open Weather API. This integration exemplifies how AWS Step Functions can manage complex logic and decisions based on external conditions, showcasing the use of this technology in a scenario that requires adaptability and precision.

Scenario: Catering Business Workflow

Imagine a catering business that needs to adjust its operations dynamically based on weather conditions. The provided state machine represents a simple workflow that combines weather data retrieval with decision-making processes facilitated by DecisionRules. This setup enables the business to make informed decisions about event planning, menu selection, and logistical arrangements, all tailored to the forecasted weather. It also handles making venue reservations and creating invoices using AWS Lambdas which interacts with the business’s management system.

What will you need?

  • An AWS account with a subscription and ideally Administrator privileges
  • A role for your state machine with the following permissions:some text
    • to Invoke Lambda Functions
    • to Invoke HTTP Endpoints and retrieve credentials via Amazon EventBridge 
    • to Access AWS Secrets Manager (Used by API Gateway to store Bearer Tokens and other sensitive information)
    • General Step Function Permissions (Start Execution, Describe execution, etc…)

The Workflow

The state machine starts by establishing a connection with the Open-Meteo API to fetch the forecast, transforms the returned data to create a request body for DecisionRules as well as the two Lambda functions. This data then informs the subsequent decision-making steps, where the business logic, managed by, determines the equipment needed for this particular event. The Input to this state machine is a simple JSON schema in which we provide the date of the event as well as the latitude and longitude of the venue.

The execution then starts, following the steps below.

1. Fetching Weather Data

The process begins with the "Create API Endpoint" state, which configures the endpoint for the Open-Meteo API. Following this setup, the "Call Weather API" state retrieves the forecast for the specified date and location, ensuring that the decision-making process is informed by the most current and relevant weather information. This information comes in the form of a weather code which can be interpreted using Open-Meteo documentation.

The request itself for our Input data looks like this:

2. Creating Request bodies

After obtaining the weather forecast, the state machine transitions to the "Create Request Body" state, where it prepares the input for based on the weather data.

In this pass state we process the response from the weather API and transform the data to prepare the request body for DecisionRules and here is where we would prepare requests for any other services or rule solves we want to run in the following parallel state labeled “Process Order”.

Below is an Amazon State Language representation of the “Get items based on weather code” state.

3. Parallel Execution for Comprehensive Decision-Making

The core of this state machine lies in its "Process Order" state, which showcases the concurrent execution of multiple tasks, each potentially leveraging for different aspects of event planning. This parallel processing capability highlights the power of AWS Step Functions to orchestrate complex, multifaceted workflows efficiently.

  • Decision-Based Item Selection: The "Get items based on weather code" branch uses to determine which items are best suited for the event based on the current weather, ensuring optimal guest comfort and event success. You can see the rule responsible for making the item picks below.
  • Dynamic Invoicing and Venue Reservation: Additional branches, like "Create invoices" and "Create venue reservation," handle other aspects of event planning, demonstrating the state machine's ability to manage diverse tasks simultaneously.

Error Handling Mechanisms

API Call Failures: The state machine includes a Catch block in the "Call Weather API" task to handle HTTP errors and timeouts. Upon encountering such errors, the workflow transitions to the "API Error Handler" state, which logs the error and concludes the execution, ensuring that failures are handled gracefully and do not compromise the entire workflow.

Parallel Execution Failures: A Catch block within the "Process Order" state captures errors from any of the parallel branches. If an error occurs, the workflow moves to the "General Error Handler" state, which logs the error and safely ends the execution. This approach ensures that errors in one branch do not halt the overall process, allowing for comprehensive error management across multiple tasks.

The Output

The state machine outputs a description of the weather as well as recommended items to bring based on the weather code provided by the weather API.

Integration Benefits and Strategic Value

  • Automation and Scalability: The use of AWS Step Functions for orchestrating these processes reduces manual intervention, automates complex decision workflows, and scales to handle multiple events or scenarios simultaneously.
  • Innovative Use of Cloud Services: This scenario exemplifies the innovative application of cloud services like AWS Step Functions and in solving real-world business challenges, showcasing the potential for cloud technology to drive operational excellence and strategic adaptability.


The advanced use case of integrating with AWS Step Functions, informed by real-time weather forecast data from the Open Weather API, demonstrates a powerful approach to automating and optimizing business decisions. This scenario not only showcases the technical capabilities of these services but also highlights the strategic value of leveraging cloud-based solutions for dynamic decision-making in business operations.

More reading