I'm working with AWS lambdas, and I need to exec a code in case of my lambda reach the 15min timeout.
I'm trying to create an EventBridge rule that detects the timeout and triggers another lambda with the code, but I cannot find the way to make it work. This is the format of the rule I'm creating:
{
"source": ["aws.lambda"],
"detail-type": ["Lambda Function Invocation Result - Failure"],
"detail": {
"functionName": ["lambda-function-name"],
"errorType": ["TimeoutError"]
}
}
The lambda that I want to track is async called by another lambda, which is called by an API event. So this is the flow:
API Gateway call -> Lambda Coordinator -> Lambda Executor.
This lambda executor is the one that I need to track and get the timeout.
I have tried several ways, but the rule is never triggered.
EventBridge rules won’t fire when a Lambda times out on an async invocation because async Lambda invocations don’t emit detailed failure events like TimeoutError to EventBridge.
Instead of trying to detect the timeout externally, wrap your Lambda call in a Step Function.
Start Execution of the state machine
The first state is "Invoke Executor"
It calls the LambdaExecutor function
It has timeout of 850/870 seconds. This timeout is a safe buffer as 900 secs might not cleanly fail.
If LambdaExecutor completes successfully the workflow ends successfully
If LambdaExecutor fails or times out
The execution transitions to "Fallback Lambda"
This function handles error cases like cleanup, alerting or retry logic.
Once Fallback Lambda finishes the workflow ends (with a failure or handled outcome)