CodexBloom - Programming Q&A Platform

AWS Step Functions Retries Not Triggering On Task Failure with Lambda

๐Ÿ‘€ Views: 67 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-09
aws lambda step-functions JavaScript

I'm trying to implement an AWS Step Function that orchestrates a series of Lambda functions. However, I'm working with an scenario where my Step Function does not seem to retry the task when a Lambda function fails with an behavior. My Lambda function is supposed to throw an exception under certain conditions, but the Step Function just terminates instead of retrying. I'm using the AWS SDK for JavaScript (v3) to define my Step Function. Hereโ€™s a simplified version of my state machine definition: ```json { "Comment": "A simple AWS Step Function example", "StartAt": "MyLambdaTask", "States": { "MyLambdaTask": { "Type": "Task", "Resource": "arn:aws:lambda:us-east-1:123456789012:function:MyLambdaFunction", "Retry": [ { "ErrorEquals": ["States.ALL"], "IntervalSeconds": 2, "MaxAttempts": 3, "BackoffRate": 2.0 } ], "End": true } } } ``` The Lambda function is designed to throw a `new behavior('Task failed')` if it encounters invalid input. I am testing this behavior by sending such input to the Lambda. However, when the Lambda throws the behavior, the entire Step Function execution fails with the message: `Task failed: Task failed to run`. Iโ€™ve also checked CloudWatch logs and confirmed that my Lambda is indeed throwing the behavior. Iโ€™ve tried adjusting the `ErrorEquals` to be more specific, but it still doesnโ€™t seem to help. I need the Step Function to retry the task automatically on failure. Am I missing something in the configuration? Any guidance on how to make the retries work would be greatly appreciated!