2

I am trying to add addCatch to a fargate task running inside step function using aws cdk Typescript Custom State.

new CustomState(this, "Failed", {
      stateJson: {
        Type: "Fail",
      },
});

const stateJson = {
  Type: 'Task',
  Resource: 'arn:aws:states:::ecs:runTask.sync',
Retry: [
        {
          ErrorEquals: ["ECS.AmazonECSException"],
          IntervalSeconds: 2,
          MaxAttempts: 6,
          BackoffRate: 2,
        }
      ],
      Catch: [
        {
          ErrorEquals: ["States.All"],
          Next: "$.Failed",
          ResultPath: "$.error",
        },
      ],
  Parameters: {
   LaunchType: "FARGATE",
        Cluster: clusterName,
        TaskDefinition: TaskDefinition,
  },
  ResultPath: '$.FargateOutput',
};

const custom = new sfn.CustomState(this, 'my custom task', {
  stateJson,
});

const chain = sfn.Chain.start(custom)
  .next(finalStatus);

const sm = new sfn.StateMachine(this, 'StateMachine', {
  definition: chain,
  timeout: Duration.seconds(30),
});

But during deployment I am getting error Invalid State Machine Definition: 'MISSING_TRANSITION_TARGET: Missing 'Next' target: $.Failed

2
  • Hi. I do not see "Next" in Catch method: docs.aws.amazon.com/cdk/api/v2/docs/… Commented Sep 23, 2022 at 11:11
  • Have you managed this case? I have absolutely the same case and can't find any way to add catch state to ecsRunTask one. Commented Jan 19, 2023 at 20:17

2 Answers 2

0

Just went through this myself and stumbled upon your question. I'm not using the ecs resource but am using a CustomState with CDK and was encountering the same error.

What I got to work was the following...

Catch: [
    {
      ErrorEquals: ["States.All"],
      Next: "Failed",  // just use the ID of your CustomState as-is
      ResultPath: "$.error",
    },
  ],
Sign up to request clarification or add additional context in comments.

Comments

0

I believe this is still an open issue with cdk and one that I ran into as well.

Unfortunately, I couldn't figure out how to solve this using a CustomState but I did manage to create an EcsRunTask state, which provides an addCatch method.

All of the props you specified in the CustomState have corresponding props in EcsRunTask.

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.