In AWS, I have a Step Function Workflow:
"GetAccountAlias": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:iam:listAccountAliases",
"Parameters": {
"MaxItems": 1
},
"ResultSelector": {
"name.$": "States.ArrayGetItem($.AccountAliases, 0)"
},
"ResultPath": "$.name",
"Next": "Update"
},
It gets an input like this:
{
"my_object_key": "123"
}
Next I retrieve the alias. Now the output is:
{
"my_object_key": "123",
"name": {
"name": "<account-alias>"
}
}
When I update "ResultPath": "$.name"
to "ResultPath": "$"
then the output is:
{
"name": "<account-alias>"
}
What I want is:
{
"my_object_key": "123",
"name": "<account-alias>"
}
How can I achieve this? (Preferably without using an additional task/stage)
2
Answers
Unfortunately, you cannot accomplish this within the same state as the input is not available in the ResultSelector. You need to do this in a subsequent Pass state (see example below).
Yes, if
my_object_key
is in the *execution* input. If not, you’ll need a Pass state, as @JustinCallison says.ResultSelector
can reference (1) the lambda task output (as$
) and (2) the step function’s execution input (as$$.Execution.Input
). Ifmy_object_key
was passed into the step function, you are in luck:What’s happening? We’re merging two JSON objects with the
States.JsonMerge
intrinsic function. Easy enough, but first we must coercename
andmy_object_key
from values to JSON key-value pairs. We manually create a stringified object withStates.Format
and then parse it withStates.StringToJson
.Here’s
ResultSelector
formatted to make it easier to see what’s going on: