Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Step Functions is not catching States.Runtime error

The below step function is executed in aws and when there is a missing of a required parameter it cancel the flow and throws States.Runtime Error. This is in catch phase of the step function but it is not catching the error as stated.

Defined Step function is as below,

{
  "StartAt": "Log Start Step Function",
  "Comment": "Executed with inputs",
  "States": {
    "Log Start Step Function": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:eu-west-1:0000000:function:update",
      "Parameters": {
        "body": {
          "itemID.$": "$.itemID",
          "functionName.$": "$.stepFunctionName ",
          "executionARN.$": "$$.Execution.Id",
          "complete": false,
          "inprogress": true,
          "error": false
        }
      },
      "Catch": [
        {
          "ErrorEquals": [
            "States.Runtime"
          ],
          "ResultPath": "$.taskresult",
          "Next": "Log Failed Module"
        },
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "ResultPath": "$.taskresult",
          "Next": "Log Failed Module"
        }

      ],
      "ResultPath": "$.taskresult",
      "Next": "Evaluate Module PA1"
    }
  }
}

Below is the step function, enter image description here

And the error thrown is as below, enter image description here

Runtime error is not executing Log failed module.

{
   "ErrorEquals": [
       "States.Runtime"
    ],
    "ResultPath": "$.taskresult",
    "Next": "Log Failed Module"
  },

Is this AWS error or something wrong with the configuration which is done here or is there any other way to validate parameters in AWS Step Functions

like image 602
shamila Avatar asked Jun 12 '20 08:06

shamila


People also ask

Is AWS Step Functions a state machine?

Step Functions is based on state machines and tasks. A state machine is a workflow. A task is a state in a workflow that represents a single unit of work that another AWS service performs. Each step in a workflow is a state.

Can step function trigger SNS?

Unfortunately not SNS. You can invoke a StepFunction from: Lambda. API Gateway.

How long can AWS step function wait?

In addition, the maximum wait time that you can specify for Standard Workflows and Express workflows is one year and five minutes respectively.


4 Answers

From https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html

A States.Runtime error is not retriable, and will always cause the execution to fail. A retry or catch on States.ALL will not catch States.Runtime errors.

like image 59
Joaquin Avatar answered Oct 19 '22 01:10

Joaquin


Your state machine is expecting the following as input:

"Parameters": {
  "body": {
    "itemID.$": "$.itemID",
    "functionName.$": "$.stepFunctionName ",
    "executionARN.$": "$$.Execution.Id",
    "complete": false,
    "inprogress": true,
    "error": false
  }
},

You need to pass them when you start a new execution instead of:

{
  "Comment": "Insert your JSON here"
}

Which you are currently passing because it comes by default as the input body of a new execution in the AWS Console.

Read more about InputPath and Parameters here: https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html

like image 29
Bassem Avatar answered Oct 18 '22 23:10

Bassem


I have the same problem.

I am beginning to think that the runtime error happens when the input path is processed, and before the catcher can be initialized. This means that try / catch to test for parameters present in the input is not possible. I also tried ChoiceState, to no avail.

So I think there is no solution but to provide every parameter you refer to in the state machine definition. But the documentation is not clear on this.

like image 1
mvtango Avatar answered Oct 19 '22 00:10

mvtango


This caught me out too. My scenario was setting the output based on the results of S3 ListObjectVersions, with the versions to be deleted in a later task. In this case, $.Versions didn't exist because there was nothing in the bucket so States.Runtime was thrown.

{
  "bucket.$": "$.Name",
  "objects.$": "$.Versions"
}

To work around this -

  1. I don't transform the result of ListObjectVersions task with ResultSelector. Instead this state simply outputs the unedited result.
  2. I added a Choice state underneath with a rule to check if $.Versions is present.
    • If it is present, move to a Pass state and transform the input in the exact same was a I was originally transforming the result of the ListObjectVersions task using the ResultSelector (because the Pass state doesn't transform on output, only input).
    • If it is not present, move to a Success state because there is nothing to delete.

Here is a screen grab of the relevant section, just in case it's helpful to visualise.

enter image description here

like image 1
David Gard Avatar answered Oct 19 '22 00:10

David Gard