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.
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.
Share Improve this question edited Mar 23 at 6:16 John Rotenstein 271k28 gold badges447 silver badges531 bronze badges Recognized by AWS Collective asked Mar 22 at 12:21 JGrimaJGrima 257 bronze badges 4 |1 Answer
Reset to default 1EventBridge 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)
detail
filter and forwarded all events e.g. to cloudwatch and inspected what gets events and what does not? What are you trying to achieve in the first place? Just monitoring or do you also want to e.g. retry the invocation in which case you would also need to somehow get access to the payload. You could set up a cloudwatch logs filter to filter for the timeout logs and go from there. – luk2302 Commented Mar 22 at 13:39MaximumRetryAttempts
so that the failed request goes to a DLQ after N attempts, and you can then react to those messages appearing in the DLQ. Also be aware that the Lambda function's context hasget_remaining_time_in_millis()
method. This can be used to determine the remaining execution time for the function (in milliseconds). – jarmod Commented Mar 23 at 0:26