[aws-stepfunctions-tasks] StepFunctionsStartExecution should receive a JSON Path at name instead a fixed string
See original GitHub issueWhen the aws-stepfunctions-tasks.StepFunctionsStartExecutionProps.name is assigned and I execute more than one NestedStateMachine, the second State Machine It try to execute fails because a State Machine with the same name already exist.
The aws-stepfunctions-tasks.StepFunctionsStartExecution
receives the name
parameter. With this name the class generates the following result:
"ExampleState": {
"Next": "NextState",
"Type": "Task",
"Resource": "arn:aws:states:::states:startExecution.sync:2",
"Parameters": {
"Input.$": "$$.Execution.Input",
"StateMachineArn": "arn:aws:states:us-east-1:123456:stateMachine:XYZ",
"Name": "ExampleName"
}
}
Reproduction Steps
- Create 2 StateMachines
- Add a Task of type
StepFunctionsStartExecution
stepfunctions_task.StepFunctionsStartExecution(
scope=scope, id="EXAMPLE_STATE",
state_machine=example_state_machine,
input=stepfunctions.TaskInput.from_context_at("$$.Execution.Input"),
integration_pattern=stepfunctions.IntegrationPattern.RUN_JOB,
name="ExampleName")
- Execute the StateMachine more than once
The minimal amount of code should be something arround this lines.
class StateMachineTwo(aws_stepfunctions.StateMachine):
def __init__(self,
scope: core.Construct) -> None:
state__task = self._create_state__processing(scope=scope)
super().__init__(
scope=scope,
id="StateMachineTwo",
definition=state__task,
timeout=core.Duration.minutes(5)
)
def _create_state__processing(self, scope):
function = aws_lambda.Function(scope=scope, id="ExampleStateTwo", code=aws_lambda.Code().from_inline(
"""def handler(event, context):
return {}"""), handler="handler", runtime=aws_lambda.Runtime.PYTHON_3_7)
return aws_stepfunctions_tasks.LambdaInvoke(scope=scope, id="EXAMPLE_STATE", lambda_function=function,
payload=aws_stepfunctions.Data.entire_payload)
class StateMachineOne(aws_stepfunctions.StateMachine):
def __init__(self,
scope: core.Construct,
state_machine_two: StateMachineTwo) -> None:
state__task = self._create_state__processing(scope=scope)
state__stepfunction = self._create_state__processing_reversion(
scope=scope, state_machine_two=state_machine_two)
state__task.next(next=state__stepfunction)
super().__init__(
scope=scope,
id="StateMachineOne",
definition=state__task,
timeout=core.Duration.minutes(5)
)
def _create_state__processing(self, scope):
function = aws_lambda.Function(scope=scope, id="ExampleStateOne", code=aws_lambda.Code().from_inline(
"""def handler(event, context):
return {}"""), handler="handler", runtime=aws_lambda.Runtime.PYTHON_3_7)
return aws_stepfunctions_tasks.LambdaInvoke(scope=scope, id="EXAMPLE_STATE", lambda_function=function,
payload=aws_stepfunctions.Data.entire_payload)
def _create_state__processing_reversion(self, scope, state_machine_two):
step_function_task = aws_stepfunctions_tasks.StepFunctionsStartExecution(
scope=scope, id="STATE_ONE",
state_machine=state_machine_two,
input=aws_stepfunctions.Data.entire_payload,
integration_pattern=aws_stepfunctions.IntegrationPattern.RUN_JOB)
return step_function_task
Error Log
{ “error”: “StepFunctions.ExecutionAlreadyExistsException”, “cause”: “Execution Already Exists: ‘arn:aws:states:us-east-1:123456789:execution:StateMachineExample:EXAMPLE_STATE’ (Service: AWSStepFunctions; Status Code: 400; Error Code: ExecutionAlreadyExists; Request ID: abcd)” }
Environment
- CLI Version : 1.47.0
- Framework Version:
- Node.js Version: 12.16
- OS : Ubuntu
- Language (Version): Python (3.7.6)
Other
I’m not sure if this classifies as Bug, or I’m failing to see something
I tried the following at the state machine in the AWS console, and execute it again, and it worked wonderfully.
"EXAMPLE_STATE": {
"Next": "NEXT_EXAMPLE_STATE",
"Type": "Task",
"Resource": "arn:aws:states:::states:startExecution.sync:2",
"Parameters": {
"Input.$": "$$.Execution.Input",
"StateMachineArn": "arn:aws:states:us-east-X:123456789:stateMachine:ExampleStateMachine",
"Name.$": "$.order.id"
}
}
The name of the nested StateMachine execution was the value of the order id.
I think if we can treat this name
attribute like a normal Parameters
attribute it would be a lot more powerful, because I can give the nested stepfunction a name that would allow me to tell apart an execution from another. For example, each execution has the ID of the order we send for shipping. So its easy to find and asses.
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
I’m dropping the
bug
label from this as I believeJsonPath
can be provided for thename
property. If that’s not the case, let me know and we can revisit.@jindriago-scf that’s great that it worked! I think the README has an example. I’ll double check the doc string and make an update if needed to help any other users that run into similar friction