To retrieve data from a dictionary using a dynamic variable in an AWS Step Function, you can use the intrinsic function States.JsonPath
and the syntax for referencing a specific key in a JSON object.
For example, if you have a dictionary stored in the state input variable ${MY_DICT}
and you want to retrieve the value for a key that is stored in another state input variable ${MY_KEY}
, you could use the following code:
"Result": {
"Type": "Task",
"Resource": "arn:aws:states:::states:jsonpath",
"Parameters": {
"$.value.$": "$.MY_DICT['$$.State.Input']['MY_KEY']"
},
"ResultPath": "$.result"
}
In this code, the $.value.$
parameter specifies where to store the result of the JSONPath expression, and the expression itself uses the ['$$.State.Input']['MY_KEY']
syntax to retrieve the value of the key stored in ${MY_KEY}
from the dictionary stored in ${MY_DICT}
. The result of the expression will be stored in the result
property of the output of this state.
Asked: 2021-05-27 11:00:00 +0000
Seen: 12 times
Last updated: May 31 '21