aws / aws/aws-cdk

stepfunctions-tasks: support whole State parameter in EvaluateExpression

Open
#20,882 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-stepfunctions-tasks bug effort/small p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

Using whole State parameter in expression is not correctly handled by EvaluateExpression.

This is useful to use optional chaining and/or nullish coalescing operator on State properties that could be possibly unsetted and referencing them directly will result in an error (eg: "The JSONPath ... could not be found in the input").

### Expected Behavior

In the final created Task, `expressionAttributeValues` should be:

``` json
"expressionAttributeValues": {
"$.$": "$"
}
```

### Current Behavior

In the final created Task, `expressionAttributeValues` is empty.

### Reproduction Steps

``` typescript
new EvaluateExpression(scope, 'Id', {
expression: '`${($).optional?.state ?? "Default"}`',
resultPath: '$.optionalStateOrDefault'
});
```

### Possible Solution

Probably updating the RegEx on this line could be enough:

https://github.com/aws/aws-cdk/blob/2a3fd5ae2369ef693d06ba5730087deba5f164ff/packages/%40aws-cdk/aws-stepfunctions-tasks/lib/evaluate-expression.ts#L73

With: `/\${1,2}[.[][.a-zA-Z[\]0-9-_]+|\${1,2}/g`

### Additional Information/Context

_No response_

### CDK CLI Version

2.28.1

### Framework Version

_No response_

### Node.js Version

14.19.3

### OS

WSL2 - Ubuntu 20.04.4

### Language

Typescript

### Language Version

TypeScript (4.7.3)

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in packages/@aws-cdk/aws-stepfunctions-tasks/lib/evaluate-expression.ts at the expression-parameter handling around line 73, using the provided EvaluateExpression reproduction as the entry point. Confirm that a whole State reference produces an expressionAttributeValues entry of "$.$": "$" in the generated Task, while preserving existing expression handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.