Create Workflows For Calculator State Machine

Create Workflows For Calculator State Machine

  1. Go to AWS Step Function Console.
  • Click Get started. Create Workflows For Calculator State Machine
  1. In the Review Hello World example page, click Next Create Workflows For Calculator State Machine
  2. In the Specify details page
  • In the State machine name section, type BasicCalculator
  • In the Permission section, select Choose an existing role
  • In the Existing roles section, select idevelop-step-functions-execution-roles Create Workflows For Calculator State Machine
  • Drag the screen down, click Create state machine.
  1. Click Cancel Create Workflows For Calculator State Machine
  2. Click Edit Create Workflows For Calculator State Machine
  3. Copy the below content over to the Defintion section
{
  "Comment": "Simple Calculator Step Functions Example",
  "StartAt": "state.start.operatorSelector",
  "States": {
    "state.start.operatorSelector": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.operator",
          "StringEquals": "add",
          "Next": "state.process.operator.add"
        },
        {
          "Variable": "$.operator",
          "StringEquals": "subtract",
          "Next": "state.process.operator.subtract"
        },
        {
          "Variable": "$.operator",
          "StringEquals": "multiply",
          "Next": "state.process.operator.multiply"
        },
        {
          "Variable": "$.operator",
          "StringEquals": "divide",
          "Next": "state.process.operator.divide"
        }
      ],
      "Default": "state.process.operator.unknown"
    },
    "state.process.operator.add": {
      "Type": "Pass",
      "Comment": "Performs an addition on the operands provided",
      "Next": "state.process.displayResult"
    },
    "state.process.operator.subtract": {
      "Type": "Pass",
      "Comment": "Performs an subtraction on the operands provided",
      "Next": "state.process.displayResult"
    },
    "state.process.operator.multiply": {
      "Type": "Pass",
      "Comment": "Performs an multiplication on the operands provided",
      "Next": "state.process.displayResult"
    },
    "state.process.operator.divide": {
      "Type": "Pass",
      "Comment": "Performs an division on the operands provided",
      "Next": "state.process.displayResult"
    },
    "state.process.operator.unknown": {
      "Type": "Fail",
      "Error": "UNKNOWN_OPERATOR",
      "Cause" : "The operator provided is not supported"
    },
    "state.process.displayResult": {
      "Type": "Pass",
      "Next": "state.process.complete"
    },
    "state.process.complete": {
      "Type": "Pass",
      "End": true
    }
  }
}
  • Click refresh icon to force the state machine to be rendered graphically
  • Click Save Create Workflows For Calculator State Machine

    Take a moment to review the state machine definition, and the graphical representation. The implementation makes decisions based on the input data, but does not perform any calculations - all the states have a Type of “Pass” which is a NOOP in State Language terms.

  1. You may see an IAM role warning. Click Save anyway Create Workflows For Calculator State Machine
  2. Click Start Excution Create Workflows For Calculator State Machine
  3. Delete the default JSON payload provided, and replace with the following JSON
{
  "operator" : "add",
  "operands" : [
      1,
      2
  ]
}
  • Click Start execution Create Workflows For Calculator State Machine
  1. you will see the results of the execution Create Workflows For Calculator State Machine
  2. Try the other operator types - divide, multiply, subtract. You will notice that although the correct paths are taken, the output shows no manipulation of the input is occurring. Lets create a microservice to do that!