Home > front end >  Invalid State Machine Definition
Invalid State Machine Definition

Time:11-26

I'm making a 4 lambda step function, leading to a gigantic JSON which is prone to errors. I put it through a JSON formatter, so I'm not sure what I'm getting wrong here. Any help appreciated, thank you.

On that note, is there a tool that would help me translate CF step functions to HCL/JSON?

This is the JSON:

{
   "StartAt":"StartState",
   "States":{
      "StartState":{
         "Type":"Pass",
         "Next":"GetLastExecutionDateTime"
      },
      "GetLastExecutionDateTime":{
         "Type":"Task",
         "Parameters":{
            "Payload.$":"$"
         },
         "Resource":"${aws_lambda_function.read.arn}",
         "Retry":{
            "ErrorEquals":[
               "States.ALL"
            ],
            "IntervalSeconds":"2",
            "MaxAttempts":"1",
            "BackoffRate":"2"
         },
         "Next":"GetDeltaRecordsNumber",
         "ResultPath":"$.lastExecutedDateTime",
         "OutputPath":"$.lastExecutedDateTime.Payload"
      },
      "GetDeltaRecordsNumber":{
         "Type":"Task",
         "Parameters":{
            "Payload.$":"$"
         },
         "Resource":"${aws_lambda_function.count.arn}",
         "Retry":{
            "ErrorEquals":[
               "States.ALL"
            ],
            "IntervalSeconds":"2",
            "MaxAttempts":"6",
            "BackoffRate":"2"
         },
         "Next":"DeltaRecordsNumber",
         "ResultPath":"$.Payload"
      },
      "DeltaRecordsNumber":{
         "Type":"Choice",
         "Choices":{
            "Variable":"$.Payload.Payload.totalRows",
            "NumericEquals":"0",
            "Next":"EndState"
         },
         "Default":"Iterator"
      },
      "Iterator":{
         "Type":"Map",
         "Next":"PassNewExecutionDateTime",
         "Iterator":{
            "StartAt":"ExecuteSqlQuery",
            "States":{
               "ExecuteSqlQuery":{
                  "Type":"Task",
                  "Resource":"${aws_lambda_function.query.arn}",
                  "OutputPath":"$.Payload",
                  "Parameters":{
                     "Payload.$":"$"
                  },
                  "End":"True"
               }
            }
         },
         "ItemsPath":"$.Payload.Payload.iterations",
         "Retry":{
            "ErrorEquals":[
               "States.ALL"
            ],
            "IntervalSeconds":"1",
            "MaxAttempts":"1",
            "BackoffRate":"1"
         },
         "Catch":{
            "ErrorEquals":[
               "States.ALL"
            ],
            "Next":"EndState",
            "ResultPath":"$.Payload"
         },
         "ResultPath":"null"
      },
      "PassNewExecutionDateTime":{
         "Type":"Pass",
         "Next":"StoreNewExecutionDateTIme",
         "OutputPath":"$.Payload.Payload"
      },
      "StoreNewExecutionDateTIme":{
         "Type":"Task",
         "Resource":"${aws_lambda_function.write.arn}",
         "OutputPath":"$.Payload",
         "Parameters":{
            "Payload.$":"$"
         },
         "Retry":{
            "ErrorEquals":[
               "States.ALL"
            ],
            "IntervalSeconds":"2",
            "MaxAttempts":"1",
            "BackoffRate":"2"
         },
         "Next":"EndState"
      },
      "EndState":{
         "Type":"Pass",
         "End":"true"
      }
   }
}

And this is the error:

╷
│ Error: error creating Step Function State Machine (dev-main-workflow): InvalidDefinition: Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: Expected value of type [ARRAY] at /States/GetLastExecutionDateTime/Retry, SCHEMA_VALIDATION_FAILED: Expected value of type [ARRAY] at /States/GetDeltaRecordsNumber/Retry, SCHEMA_VALIDATION_FAILED: Expected value of type [ARRAY] at /States/DeltaRecordsNumber/Choices, SCHEMA_VALIDATION_FAILED: Expected value of type Boolean at /States/Iterator/Iterator/States/ExecuteSqlQuery/End, SCHEMA_VALIDATION_FAILED: Expected value of type [ARRAY] at /States/Iterator/Retry, SCHEMA_VALIDATION_FAILED: Expected value of type [ARRAY] at /States/Iterator/Catch, SCHEMA_VALIDATION_FAILED: Value is not a Reference Path: Reference path didn't start with '$' at /States/Iterator/ResultPath, SCHEMA_VALIDATION_FAILED: Expected value of type [ARRAY] at /States/StoreNewExecutionDateTIme/Retry, SCHEMA_VALIDATION_FAILED: Expected value of type Boolean at /States/EndState/End, MISSING_END_STATE: Workflow has no terminal state at null, MISSING_TRANSITION_TARGET: State "Iterator" is not reachable. at /States/Iterator'
│ 
│   with aws_sfn_state_machine.main-workflow,
│   on step-function.tf line 3, in resource "aws_sfn_state_machine" "main-workflow":
│    3: resource "aws_sfn_state_machine" "main-workflow" {
│ 
╵

CodePudding user response:

Array missing here, it should be like

"Resource":"${aws_lambda_function.read.arn}",
         "Retry":[{
            "ErrorEquals":[
               "States.ALL"
            ],
            "IntervalSeconds":"2",
            "MaxAttempts":"1",
            "BackoffRate":"2"
         },]

Your choice flow also have the same problem, it should be

 "DeltaRecordsNumber":{
     "Type":"Choice",
     "Choices":[
       {
        "Variable":"$.Payload.Payload.totalRows",
        "NumericEquals": 0,
        "Next":"EndState"
     }
                ],
     "Default":"Iterator"
  },

There are more retries in your JSON doc, where you need to array instead of object.

  • Related