aws_stepfunctions: JsonPath.MathAdd does not accept expressions as parameters
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 74
Description
### Describe the bug
JsonPath.MathAdd does not accept expressions as parameters. It runs well with JsonPath.numberAt, but fails when more complex Inartistic Function expression is used. Example: last element of exploded string:
```
parameters={
"Bucket": "my-target-bucket",
"Key": _sfn.JsonPath.format(
"year={}/month={}/{}",
_sfn.JsonPath.string_at("$.Year"),
_sfn.JsonPath.string_at("$.Month"),
_sfn.JsonPath.array_get_item(
_sfn.JsonPath.string_split(
_sfn.JsonPath.string_at("$.SomeBranch.Contents[0].Key"),
"/"
),
_sfn.JsonPath.number_at(
_sfn.JsonPath.math_add(
_sfn.JsonPath.number_at(
_sfn.JsonPath.array_length(
_sfn.JsonPath.string_split(
_sfn.JsonPath.string_at("$.SomeBranch.Contents[0].Key"),
"/"
)
),
),
-1
)
)
)
),
"CopySource": _sfn.JsonPath.format(
f"{parent.config.s3['LandingZone']['Bucket'].bucket_name}/{{}}",
_sfn.JsonPath.string_at("$.SomeBranch.Contents[0].Key")
)
},
```
### Expected Behavior
This should be rendered as:
```
"Parameters": {
"Bucket": "my-target-bucket",
"Key.$": "States.ArrayGetItem(States.StringSplit($.SomeBranch.Contents[0].Key, '/'), States.MathAdd(States.ArrayLength(States.StringSplit($.SomeBranch.Contents[0].Key, '/')), -1))",
"Len.$": "States.MathAdd(States.ArrayLength(States.StringSplit($.SomeBranch.Contents[0].Key, '/')), -1)",
"CopySource.$": "States.Format('my-source-bucket/{}', $.SomeBranch.Contents[0].Key)"
}
```
### Current Behavior
Runtime error:
```
RuntimeError: Error: JSON path values must be exactly '$', '$$', start with '$.', start with '$$.', start with '$[', or start with an intrinsic function: States.Array, States.ArrayPartition, States.ArrayContains, States.ArrayRange, States.ArrayGetItem, States.ArrayLength, States.ArrayUnique, States.Base64Encode, States.Base64Decode, States.Hash, States.JsonMerge, States.StringToJson, States.JsonToString, States.MathRandom, States.MathAdd, States.StringSplit, States.UUID, or States.Format. Received: ${Token[States.ArrayLength.States.StringSplit...LandingZonePartitionObjects.Contents.0..Key........635]}
```
This points, that tokens are not accepted on the input. Only JsonPaths
### Reproduction Steps
Create simple State Machine in Python
### Possible Solution
Allow tokens
### Additional Information/Context
_No response_
### CDK CLI Version
2.64.0 (build fb67c77)
### Framework Version
_No response_
### Node.js Version
v18.12.1
### OS
OS X 13.2
### Language
Python
### Language Version
Python 3.9.6
### Other information
_No response_
Contributor guide
Research direction
Start at the JsonPath.math_add entry point and trace how its arguments are rendered when nested in the reported Python State Machine expression. Reproduce the example with CDK CLI 2.64.0 and compare the generated Parameters to the expected States.MathAdd, States.ArrayLength, and related intrinsic expressions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100