Closed kimyx closed 5 months ago
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 cause
keyword either. With this change:
fail_job = _aws_stepfunctions.Fail(
self, "Fail",
error_path=error_path, # works
cause=cause_path # fails
)
The cdk deploy command oddly fails like this:
No stacks match the name(s) JobPollerStack
In my full code, it seems to deploy, but it fails when actually running the step function.
This now works in my real app:
error_parameters = {
"Cause.$": "States.StringToJson($.Cause)",
}
# this state converts escaped json into a json object suitable for selections in the next state
error_state = sfn.Pass(self, f'ConvertErrorCause_{error_task_identifier}',
parameters=error_parameters)
format_parameters = {
"ErrorMsg.$": "States.Format('Step Function Fail: {}', $.Cause.Attempts[0].StatusReason)",
"CauseMsg.$": "States.Format('LogStreamName: {}', $.Cause.Container.LogStreamName)",
}
# this state formats error and cause strings for the following states
format_state = sfn.Pass(self, f'FormatErrorCause_{error_task_identifier}',
parameters=format_parameters)
subject = sfn.JsonPath.string_at("$.ErrorMsg")
message = sfn.TaskInput.from_text(sfn.JsonPath.string_at("$.CauseMsg"))
# SNS publish error message
failed_job_sns_topic = tasks.SnsPublish(self,
f'FailedJobMessage_{error_task_identifier}',
topic=sns_topic,
subject=subject,
message=message,
result_path="$.result"
)
error_path = "$.ErrorMsg"
cause_path = "$.CauseMsg"
fail_state = sfn.Fail(self, f"FailStepFunction_{error_task_identifier}",
error_path=error_path,
cause_path=cause_path
)
map_state.add_catch(error_state.next(format_state).next(failed_job_sns_topic).next(fail_state))
@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.
@kimyx Please advise on how you were able to come up with expression $.Cause.Container.LogStreamName
.
Thanks, Ashish
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 CausePath
should support an intrinsic function that returns a string. However, it's returning the mentioned error, perhaps here.
I am working on this issue.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
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