Search code examples
python-3.xlambdaaws-step-functions

python custom exception retry in aws step function


I am working with step functions and lambdas.I have read documentation how to do retries on various exceptions, but i didn't able to find what if i have created custom exception in python lambda and if that exception is raised how to use that exception in stepfunction retry block like this:

"ErrorEquals": [
          "Lambda.ServiceException",
          "Lambda.AWSLambdaException",
          "Lambda.SdkClientException"
        ]

suppose my lambda has following custom exception:

try:
    sometask
except Exception as e:
    raise MYEXCEPTION(f"my custom exception{e}")

how to do retry in step function , something which i expect is :

"ErrorEquals": [
          "MYEXCEPTION"
        ]

If my python lambda gives this custom exception please retry in step function, for that i need to understand how to match it in ErrorEquals in retry block.


Solution

  • Your expectation is correct, the catch block will look like

    "ErrorEquals": [ "MYEXCEPTION" ]
    

    Find more information here https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-handling-error-conditions.html