serverless-step-functions-local icon indicating copy to clipboard operation
serverless-step-functions-local copied to clipboard

Local Retry mechanism when throwing errors

Open richlloydmiles opened this issue 3 years ago • 3 comments

When a JavaScript error is thrown within a Task state that has a retry it ends the node server with an error. Is there any way to avoid this, to replicate error handling on AWS locally?

My code is as follows:

serverless.yml

FinalState:
  Type: Task
  Resource: 
    Fn::GetAtt: [world, Arn]
  Retry:
  - ErrorEquals: ["States.ALL"]
    IntervalSeconds: 1
    MaxAttempts: 5
    BackoffRate: 2

world function in handler:

module.exports.world = async event => {
  const num = Math.floor(Math.random() * 2) + 1
  if (num === 1) {
    throw new Error('Failed')
  }

  return { message: 'Success', event }
}

(the function just basically generates a random number between one and two, if the number is 1 then it fails, so this function should fail 50% of the time).

richlloydmiles avatar Sep 16 '21 07:09 richlloydmiles

I'm not sure to be honest. I've not used this for something like 2 years and I don't really remember how step function error handling works.

Happy to look over any PR if you wanna submit one. 😛

codetheweb avatar Sep 16 '21 19:09 codetheweb

Hey @codetheweb , curious about which package are you using now to run Step Functions in the local environment. Would you mind sharing the info?

Thanks!

non-senses avatar Feb 25 '22 22:02 non-senses

Well, I could rant about serverless not living up to the hype.

But I'll just leave it at that I don't use step functions (or really any other niche AWS products) anymore. 😉

codetheweb avatar Feb 25 '22 23:02 codetheweb