'aws step function choice invalid path

Having a similar issue to this post: AWS Step Function returns condition path references error

However, I am still getting the same error.

Step code:

{
 "StartAt": "get_active_facebook_ad_accounts_lambda",
 "States": {
   "get_active_facebook_ad_accounts_lambda": {
     "Type": "Task",
     "Resource": "arn:aws:states:::lambda:invoke",
     "Parameters": {
       "FunctionName": "gods_country"
      },
     "OutputPath": "$.Payload",
     "Next": "ChoiceState"
},
   "ChoiceState": {
     "Type" : "Choice",
      "Choices": [
        {
          "Variable": "$.input",
          "NumericEquals": 1,
          "Next": "DefaultState"
        },
        {
          "Variable": "$.input",
          "NumericEquals": 0,
          "Next": "EndState"
        }
      ]
  },
   "DefaultState": {
      "Type": "Fail"
   },
   "EndState": {
     "Type": "Succeed"
   }
}
}

Execution plan errors: enter image description here



Solution 1:[1]

It looks like your function is just returning a number. If this is the case you can likely do something like this:

{
 "StartAt": "get_active_facebook_ad_accounts_lambda",
 "States": {
   "get_active_facebook_ad_accounts_lambda": {
     "Type": "Task",
     "Resource": "arn:aws:states:::lambda:invoke",
     "Parameters": {
       "FunctionName": "gods_country"
      },
     "ResultPath": "$.activeAccounts",
     "Next": "ChoiceState"
},
   "ChoiceState": {
     "Type" : "Choice",
      "Choices": [
        {
          "Variable": "$.activeAccounts",
          "NumericEquals": 1,
          "Next": "DefaultState"
        },
        {
          "Variable": "$.activeAccounts",
          "NumericEquals": 0,
          "Next": "EndState"
        }
      ]
  },
   "DefaultState": {
      "Type": "Fail"
   },
   "EndState": {
     "Type": "Succeed"
   }
}
}

OutputPath is used to only pass a portion of the result on to the next step. So your previous state machine was looking for a property called Payload coming from the result of your lambda. I don't think this is the case - it looks like the result is just a number.

ResultPath specifies where the result of the step should be stored, and allows us to combine this result with any previous state. In this case in $.activeAccounts. You can then reference that property in subsequent steps.

For further information check out the AWS filtering documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 x112358