0

I have a AWS step function defined in the C# CDK where one of the states is a task as defined as such:

var executeGlueJobStepFunction = new CustomState(this, "ExecuteGlueJobStepFunction", new CustomStateProps
{
    StateJson = new Dictionary<string, object>
        {
            { "Type", "Task" },
            { "Resource", "arn:aws:states:::states:startExecution.sync:2" },
            { "Parameters", new Dictionary<string, object>
                {
                    { "StateMachineArn.$", JsonPath.Format($"arn:aws:states:{Stack.Of(this).Region}:{Stack.Of(this).Account}:stateMachine:{{}}", JsonPath.StringAt("$.stepFunctionName")) },
                    { "Input.$", JsonPath.EntirePayload }
                }
            },
            { "ResultSelector", new Dictionary<string,object>
                {
                    { "Output.$", "$.Output" }
                }
            },
        },
});

This starts executing another step function that triggers a glue job run synchronously.

Now, when the caller step function fails or is aborted, the child execution (and the glue job run) continues to completion.

Is there a way I can change this behaviour so that the child execution and glue job run are terminated if the caller step function fails?

1 Answer 1

0

When dealing with nested Step Functions executions, adding StopNewExecution: true to the Parameters solved this issue. Here's how you can try to modify the CDK code:

var executeGlueJobStepFunction = new CustomState(this, "ExecuteGlueJobStepFunction", new CustomStateProps
{
    StateJson = new Dictionary<string, object>
    {
        { "Type", "Task" },
        { "Resource", "arn:aws:states:::states:startExecution.sync:2" },
        { "Parameters", new Dictionary<string, object>
            {
                { "StateMachineArn.$", JsonPath.Format($"arn:aws:states:{Stack.Of(this).Region}:{Stack.Of(this).Account}:stateMachine:{{}}", JsonPath.StringAt("$.stepFunctionName")) },
                { "Input.$", JsonPath.EntirePayload },
                { "StopNewExecution", true }  // This parameter does the trick
            }
        },
        { "ResultSelector", new Dictionary<string,object>
            {
                { "Output.$", "$.Output" }
            }
        },
    },
});

Just be aware there might be a slight delay between the parent stopping and the child execution/Glue job terminating. This worked perfectly in our production environment.

Let me know how it goes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.