-
Notifications
You must be signed in to change notification settings - Fork 4.5k
step function: Fail state cause_path generates error using States.Format #30063
Copy link
Copy link
Closed
Closed
Copy link
Labels
@aws-cdk/aws-lambdaRelated to AWS LambdaRelated to AWS LambdabugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp1
Description
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:
RuntimeError: Expected JSON path to start with '$', got: States.Format('LogStreamName: {}', $.Cause.Container.LogStreamName)
Expected Behavior
I expected to be able to use States.Format when building a Fail state.
Current Behavior
$ cdk deploy --exclusively JobPollerStack
...
jsii.errors.JavaScriptError:
Error: Expected JSON path to start with '$', got: States.Format('LogStreamName: {}', $.Cause.Container.LogStreamName)
at renderJsonPath (/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/jsii-kernel-3Ir8Er/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/state.js:1:9755)
at Fail.toStateJson (/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/jsii-kernel-3Ir8Er/node_modules/aws-cdk-lib/aws-stepfunctions/lib/states/fail.js:1:1050)
at StateGraph.toGraphJson (/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/jsii-kernel-3Ir8Er/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-graph.js:1:2159)
at ChainDefinitionBody.bind (/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/jsii-kernel-3Ir8Er/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-machine.js:1:12008)
at new StateMachine (/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/jsii-kernel-3Ir8Er/node_modules/aws-cdk-lib/aws-stepfunctions/lib/state-machine.js:1:6368)
at Kernel._Kernel_create (/private/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/tmpv90l1_x_/lib/program.js:10108:25)
at Kernel.create (/private/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/tmpv90l1_x_/lib/program.js:9779:93)
at KernelHost.processRequest (/private/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/tmpv90l1_x_/lib/program.js:11696:36)
at KernelHost.run (/private/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/tmpv90l1_x_/lib/program.js:11656:22)
at Immediate._onImmediate (/private/var/folders/_b/2b2x6djs2q77mc8d8pt49r0m007nfk/T/tmpv90l1_x_/lib/program.js:11657:46)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/kiko1739/code/csds/src/csds_app.py", line 682, in <module>
job_poller_stack = JobPollerStack(app, 'BadStack')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/kiko1739/code/csds/venv_311/lib/python3.11/site-packages/jsii/_runtime.py", line 118, in __call__
inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/kiko1739/code/csds/src/stacks/step_bad_stack.py", line 85, in __init__
sm = _aws_stepfunctions.StateMachine(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/kiko1739/code/csds/venv_311/lib/python3.11/site-packages/jsii/_runtime.py", line 118, in __call__
inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/kiko1739/code/csds/venv_311/lib/python3.11/site-packages/aws_cdk/aws_stepfunctions/__init__.py", line 10097, in __init__
jsii.create(self.__class__, self, [scope, id, props])
File "/Users/kiko1739/code/csds/venv_311/lib/python3.11/site-packages/jsii/_kernel/__init__.py", line 334, in create
response = self.provider.create(
^^^^^^^^^^^^^^^^^^^^^
File "/Users/kiko1739/code/csds/venv_311/lib/python3.11/site-packages/jsii/_kernel/providers/process.py", line 365, in create
return self._process.send(request, CreateResponse)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/kiko1739/code/csds/venv_311/lib/python3.11/site-packages/jsii/_kernel/providers/process.py", line 342, in send
raise RuntimeError(resp.error) from JavaScriptError(resp.stack)
RuntimeError: Expected JSON path to start with '$', got: States.Format('LogStreamName: {}', $.Cause.Container.LogStreamName)
Subprocess exited with error 1
Reproduction Steps
# adapted from https://github.com/aws-samples/aws-cdk-examples/blob/main/python/stepfunctions/stepfunctions/stepfunctions_stack.py
from aws_cdk import (
aws_stepfunctions as _aws_stepfunctions,
App, Duration, Stack
)
class JobPollerStack(Stack):
def __init__(self, app: App, id: str, **kwargs) -> None:
super().__init__(app, id, **kwargs)
# Step functions Definition
submit_job = _aws_stepfunctions.Wait(
self, "Submit Job",
time=_aws_stepfunctions.WaitTime.duration(
Duration.seconds(30))
)
wait_job = _aws_stepfunctions.Wait(
self, "Wait 30 Seconds",
time=_aws_stepfunctions.WaitTime.duration(
Duration.seconds(30))
)
status_job = _aws_stepfunctions.Wait(
self, "Get Status",
time=_aws_stepfunctions.WaitTime.duration(
Duration.seconds(30))
)
error_path = "$.Cause.Attempts[0].StatusReason"
cause_path = "States.Format('LogStreamName: {}', $.Cause.Container.LogStreamName)"
fail_job = _aws_stepfunctions.Fail(
self, "Fail",
error_path=error_path, # works
cause_path=cause_path # fails
)
succeed_job = _aws_stepfunctions.Succeed(
self, "Succeeded",
comment='AWS Batch Job succeeded'
)
# Create Chain
chain = submit_job.next(wait_job) \
.next(status_job) \
.next(_aws_stepfunctions.Choice(self, 'Job Complete?')
.when(_aws_stepfunctions.Condition.string_equals('$.status', 'FAILED'), fail_job)
.when(_aws_stepfunctions.Condition.string_equals('$.status', 'SUCCEEDED'), succeed_job)
.otherwise(wait_job))
# Create state machine
sm = _aws_stepfunctions.StateMachine(
self, "StateMachine",
definition_body=_aws_stepfunctions.DefinitionBody.from_chainable(chain),
timeout=Duration.minutes(5),
)
# in app.py:
# job_poller_stack = JobPollerStack(app, 'BadStack')
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-lambdaRelated to AWS LambdaRelated to AWS LambdabugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp1