I am curious to know if it is possible to use certain intrinsic function as part of my state machine definition with respect to a choice node.
My use case is that I have a payload that comes from a queue that includes varying bits of information, however the important one is part of the "body" field. I fetch that field in my first step as follows:
FormatData": {
"Type": "Pass",
"Next": "ChooseWhichCampaignToCreate",
"InputPath": "$[0].body",
"OutputPath": "$"
},
This is all fine and well, however, the actual output is a string that is formatted as JSON. Not a straight JSON object. As such, in my next state I have to convert the Output ("$") to a JSON object as so:
"CreateSessionInviteCampaign": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "Coaching-EmailCampaign-Prepare",
"Payload.$": "States.StringToJson($)"
},
"Next": "ChoseWhichCampaignToPrepare"
},
I am rewriting it a bit to include some more choice nodes in order to make sure that each lambda has a specific bounded context and does the least amount of work it needs to do. As such I took a look at the specs (https://states-language.net/#state-types) and based on the table a Choice
state cannot have a Parameters
field, but can have an InputPath
. Is it possible to apply the intrinsic function of StringToJson
to the InputPath to have something like this:
States.StringToJson($).CampaignType
or do I need to make another simple Pass
through step after my format that would take the Input, JSONify it, and then proceed onwards like so (assuming it is correct, I would like to not have to define a basic lambda that json does a string to json):
"JSONIfyOutput": {
"Type": "Pass",
"Parameters": {
"Payload.$": "States.StringToJson($)"
},
"OutputPath": "$"
},
According to the table of where intrinsic functions are supported, you cannot use them in a Choice, but can be used on Pass Parameters. Using your intrinsic function on Parameters via Transform input with Parameters
will work.