Is it possible to add new key/value to InputPath?

Viewed 718

I need to expand InputPath of Step Functions state with a new property without changing the structure of the initial InputPath.

For instance, my InputPath looks like:

{
    "key1": "value1",
    "key2": "value2"
}

I need to add here a new pair of key/value and pass this to Lambda. Thus, what I want to have is:

{
   "key1": "value1",
   "key2": "value2",
   "key3": "value3"
}

But I haven't found the way how to implement this. What I was able to do is to change the structure of InputPath using Parameters:

"InputPath": "$",
"Parameters": {
    "input.$": "$",
    "newValue": "value3"
}

So I get JSON with the following structure:

{
    "input": {
        "key1": "value1",
        "key2": "value2"
    },
    "key3": "value3"
}

It's not a big problem, but I wonder if there is a way to keep a flat structure of InputPath and not to add new attributes (like "input" in my example).

UPD: I'm aware that it can be implemented using Pass states, but state machine is going to become too massive then.

1 Answers

Yes, it's possible to flatten the structure. Try following

"InputPath": "$",
"Parameters": {
    "key1.$": "$.key1",
    "key2.$": "$.key2",
    "key3": "value3"
}

Please refer InputPaths and Parameters for more details.

Edit

Since you want to pass the new value to your Lambda function, I'm assuming that your state is of type Task. Task state offers support for parameters. So, you don't need a Pass state to achieve the same.

Related