1 Answer
- Newest
- Most votes
- Most comments
1
When a Step Functions Task state times out while invoking a Lambda function, the Lambda function continues to run in the background until it either completes or reaches its own configured timeout limit. Step Functions does not have the ability to terminate or stop the Lambda function execution when the Task state timeout is reached.
Here's what happens in your specific scenario:
- The Step Functions Task state will wait for up to 5 minutes (300 seconds as specified by TimeoutSeconds) for the Lambda function to complete
- If the Lambda function doesn't respond within those 5 minutes, Step Functions will mark the Task state as failed with a States.Timeout error
- The Lambda function will continue executing independently until it either:
- Completes its work (up to the 15-minute Lambda timeout)
- Reaches its own 15-minute timeout and is terminated by Lambda itself
This means the Lambda function becomes "orphaned" from the Step Functions workflow perspective. The workflow will have already moved on (either to an error handler, retry logic, or marked as failed), while the Lambda function continues processing in the background.
To handle this scenario effectively, you should:
- Set the Task state TimeoutSeconds to be less than or equal to your Lambda function timeout to avoid unnecessary waiting
- Implement proper error handling using Retry and Catch fields in your Task state definition
- Consider implementing idempotency in your Lambda functions to handle potential retry scenarios
- Be aware that you'll be charged for the full Lambda execution time, even after the Step Functions Task state has timed out
Sources
Handling errors in Step Functions workflows - AWS Step Functions
Task workflow state - AWS Step Functions
Relevant content
- asked 4 years ago
