You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(stepfunctions): cannot use intrinsic functions in Fail state (#30210)
### Issue # (if applicable)
Closes#30063
### Reason for this change
In the Fail state, we can specify intrinsic functions and json paths as the CausePath and ErrorPath properties.
Currently, however, specifying intrinsic functions as a string will result in an error.
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html
```ts
export class SampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const fail = new stepfunctions.Fail(this, "Fail", {
errorPath: "$.error", // OK
causePath: "States.Format('cause: {}', $.cause)", // Error
});
const sm = new stepfunctions.StateMachine(this, "StateMachine", {
definitionBody: stepfunctions.DefinitionBody.fromChainable(fail),
timeout: cdk.Duration.minutes(5)
});
}
}
```
```
Error: Expected JSON path to start with '$', got: States.Format('cause: {}', $.cause)
```
### Description of changes
The value passed to the `renderJsonPath` function is expected to be a string starting with `$` if it is not a token.
However, if you pass intrinsic functions as strings to the CausePath and ErrorPath properties, they will never start with `$`.
Therefore, I fixed not to call the `renderJsonPath` function if the intrinsic functions are specified as strings.
Another change was the addition of validation since error and errorPath, cause and causePath cannot be specified simultaneously.
### Description of how you validated changes
I added unit tests to verify that passing intrinsic functions as strings do not cause an error.
Tests were also added to verify that errors occur when errors and paths are specified at the same time and when cause and cause paths are specified at the same time.
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html#:~:text=%2C%20and%20States.UUID.-,Important,-You%20can%20specify%20either%20Causehttps://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html#:~:text=%2C%20and%20States.UUID.-,Important,-You%20can%20specify%20either%20Error
### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
You can also use an intrinsic function that returns a string to specify CausePath and ErrorPath.
491
+
The available functions include States.Format, States.JsonToString, States.ArrayGetItem, States.Base64Encode, States.Base64Decode, States.Hash, and States.UUID.
Copy file name to clipboardExpand all lines: packages/aws-cdk-lib/aws-stepfunctions/lib/states/fail.ts
+53-3
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
import{Construct}from'constructs';
2
2
import{StateType}from'./private/state-type';
3
3
import{renderJsonPath,State}from'./state';
4
+
import{Token}from'../../../core';
4
5
import{INextable}from'../types';
5
6
6
7
/**
@@ -31,6 +32,9 @@ export interface FailProps {
31
32
/**
32
33
* JsonPath expression to select part of the state to be the error to this state.
33
34
*
35
+
* You can also use an intrinsic function that returns a string to specify this property.
36
+
* The allowed functions include States.Format, States.JsonToString, States.ArrayGetItem, States.Base64Encode, States.Base64Decode, States.Hash, and States.UUID.
37
+
*
34
38
* @default - No error path
35
39
*/
36
40
readonlyerrorPath?: string;
@@ -45,6 +49,9 @@ export interface FailProps {
45
49
/**
46
50
* JsonPath expression to select part of the state to be the cause to this state.
47
51
*
52
+
* You can also use an intrinsic function that returns a string to specify this property.
53
+
* The allowed functions include States.Format, States.JsonToString, States.ArrayGetItem, States.Base64Encode, States.Base64Decode, States.Hash, and States.UUID.
54
+
*
48
55
* @default - No cause path
49
56
*/
50
57
readonlycausePath?: string;
@@ -56,6 +63,16 @@ export interface FailProps {
56
63
* Reaching a Fail state terminates the state execution in failure.
57
64
*/
58
65
exportclassFailextendsState{
66
+
privatestaticallowedIntrinsics=[
67
+
'States.Format',
68
+
'States.JsonToString',
69
+
'States.ArrayGetItem',
70
+
'States.Base64Encode',
71
+
'States.Base64Decode',
72
+
'States.Hash',
73
+
'States.UUID',
74
+
];
75
+
59
76
publicreadonlyendStates: INextable[]=[];
60
77
61
78
privatereadonlyerror?: string;
@@ -80,9 +97,42 @@ export class Fail extends State {
0 commit comments