The StepFunctions implementation of JsonPath allow us to filter elements using the ?()
syntax.
When I try to test a state machine that use a filter, the validation fails and if I try to bypass the validation, the engine returns an error.
import { StateMachine } from 'aws-local-stepfunctions';
const machineDefinition = JSON.parse(JSON.stringify({
StartAt: 'GetSubjects',
States: {
GetSubjects: {
Type: 'Task',
Resource: 'arn:aws:lambda:us-east-1:123456789012:function:GetSubjects',
Next: 'ReturnResult'
},
ReturnResult: {
Type: 'Pass',
Parameters: {
'completed_los.$': '$.Payload[?(@.subject_status==subject_completed)]..subject_id',
},
End: true
}
},
}));
test('OK', async () => {
// GIVEN
const myInput = {};
// WHEN
const stateMachine = new StateMachine(machineDefinition, {
// validationOptions: {
// checkPaths: false,
// }
});
const execution = stateMachine.run(myInput, {
overrides: {
taskResourceLocalHandlers: {
"GetSubjects": ((event: any) => {
return {
Payload: [
{ subject_id: 1, subject_status: 'subject_completed' },
{ subject_id: 2, subject_status: 'subject_completed' },
{ subject_id: 3, subject_status: 'subject_added' }
]
}
})
},
},
});
const result = await execution.result;
console.log(result);
// THEN
expect(result).toStrictEqual([1,2]);
});
The state machine should process the JsonPath filter.
tate machine definition is invalid, see error(s) below:
SCHEMA_VALIDATION_FAILED: /States/ReturnResult/Parameters/completed_los.$ is invalid. must match format "asl_payload_template"
ExecutionError: Execution has failed with the following error: jsonPath: subject_completed is not defined: @.subject_status==subject_completed
To make it work, I could pre-process the state machine definition to double quote any jsonpath expression, but that would be quite a good effort, moreover, I'm not keen to disable validations.