-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
step function: Fail state cause_path generates error using States.Format #30063
step function: Fail state cause_path generates error using States.Format #30063
Comments
We can probably work around this issue by inserting a Pass state before the Fail state. The Pass state selects fields and formats error/cause strings to the output that becomes input to the Fail state, which can then use a simple selection to get what it needs. Will try it soon. |
I should say, it doesn't work using the
The cdk deploy command oddly fails like this:
In my full code, it seems to deploy, but it fails when actually running the step function. |
This now works in my real app:
|
@kimyx Good afternoon. I'm unsure if this issue is specific to CDK using Python. I tried reproducing the issue using both TypeScript and Python, they both produce the same error. TypeScriptCDK stackimport * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions';
export class TypescriptStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const submit_job = new stepfunctions.Wait(this, "Submit Job", {
time: stepfunctions.WaitTime.duration(cdk.Duration.seconds(30))
});
const wait_job = new stepfunctions.Wait(this, "Wait 30 Seconds", {
time: stepfunctions.WaitTime.duration(cdk.Duration.seconds(30))
});
const status_job = new stepfunctions.Wait(this, "Get Status", {
time: stepfunctions.WaitTime.duration(cdk.Duration.seconds(30))
});
const error_path = "$.Cause.Attempts[0].StatusReason"
const cause_path = "States.Format('LogStreamName: {}', $.Cause.Container.LogStreamName)"
const fail_job = new stepfunctions.Fail(this, "Fail", {
errorPath: error_path,
causePath: cause_path
});
const succeed_job = new stepfunctions.Succeed(this, "Succeeded", {
comment: "AWS Batch Job succeeded"
});
// Create Chain
const chain = submit_job.next(wait_job)
.next(status_job)
.next(new stepfunctions.Choice(this, 'Job Complete?')
.when(stepfunctions.Condition.stringEquals('$.status', 'FAILED'), fail_job)
.when(stepfunctions.Condition.stringEquals('$.status', 'SUCCEEDED'), succeed_job)
.otherwise(wait_job));
// Create state machine
const sm = new stepfunctions.StateMachine(this, "StateMachine", {
definitionBody: stepfunctions.DefinitionBody.fromChainable(chain),
timeout: cdk.Duration.minutes(5)
});
}
}
|
Thanks for confirming, Ashish. The LogStreamName expression comes from my real app, which uses a step function to start Batch jobs, each of which produces a log stream. I didn't know a good expression for the sample app, but it failed with the same error my real app was getting. Once the initial error is fixed, let me know if you want help finding an applicable expression to test. |
Looks like as reported in the issue description, per StepFunctions: States: Fail documentation, using |
I am working on this issue. |
) ### 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%20Cause 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%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*
|
…#30210) ### Issue # (if applicable) Closes aws#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%20Cause 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%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*
…#30210) ### Issue # (if applicable) Closes aws#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%20Cause 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%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*
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one. |
Describe the bug
The AWS documentation for Fail state says that the CausePath argument accepts the use of intrinsic functions as well as reference paths. The CDK support for the Fail state works with reference paths but not with intrinsic functions, particularly
States.Format()
. It generates this error:Expected Behavior
I expected to be able to use States.Format when building a Fail state.
Current Behavior
Reproduction Steps
error_path works as given, cause_path doesn't.
Possible Solution
I'm guessing that cdk simply doesn't implement this AWS feature yet, since CausePath and ErrorPath were implemented only about 9/2023. If so, please consider this a vote for supporting it.
Additional Information/Context
No response
CDK CLI Version
CDK 2.140.0 (build 46168aa)
Framework Version
No response
Node.js Version
v20.12.1
OS
ProductName: MacOS ProductVersion: 14.3.1 BuildVersion: 23D60
Language
Python
Language Version
Python (3.11.9)
Other information
No response
The text was updated successfully, but these errors were encountered: