I have just started exploring AWS step functions & I'm trying to create a state machine that invokes a Lambda function to generate random integers. The state machine then uses the Lambda function output in a Choice state to determine the execution flow.
For example, if the Lambda function generates a number < 10, the Choice state moves to a Fail state. If the Lambda function generates a number > 10, the Choice state moves to a Pass state and workflow execution completes.
Error:
The choice state's condition path references an invalid value.
{
"Comment": "An example of input output processing",
"StartAt": "getScore",
"States": {
"getScore": {
"Type": "Task",
"Resource": "arn:aws:lambda:***:function:random-num",
"ResultPath": "$.result",
"OutputPath": "$.result",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 3,
"BackoffRate": 2
}
],
"Next": "checkScoreValue"
},
"checkScoreValue": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.result.latest",
"NumericLessThan": 40,
"Next": "Fail"
},
{
"Variable": "$.result.latest",
"NumericGreaterThan": 41,
"Next": "Pass"
}
],
"Default": "Pass"
},
"Pass": {
"Type": "Pass",
"Result": "You have passed",
"End": true
},
"Fail": {
"Type": "Fail",
"Cause": "You have failed!"
}
}
}
Error:
An error occurred while executing the state 'checkScoreValue' (entered at the event id #7). Invalid path '$.result.latest': The choice state's condition path references an invalid value.
Lambda function code:
exports.handler = async function(event, context) {
const randNumber = Math.floor( 50 * Math.random() );
return randNumber;
};