Find Lambda timeouts with CloudWatch Logs Insights
When a Lambda invocation hits its timeout, the function's log group gets a line containing "Task timed out after N seconds". Filter for that text, parse out the request ID and the timeout value, and you have a list of every timed-out invocation; aggregate by bin() to see when they started.
The query
fields @timestamp, @message, @logStream
| filter @message like /Task timed out after/
| parse @message /(?<rid>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}) Task timed out after (?<limitSec>[0-9.]+) seconds/
| display @timestamp, rid, limitSec, @logStream
| sort @timestamp desc
| limit 100How it works
fieldsbrings in the timestamp, raw message and log stream.filter @message like /Task timed out after/matches the line Lambda writes when it stops an invocation at the timeout. It's emitted by the platform, so it appears regardless of runtime or logging library.parsewith a regex and named groups pulls the request ID (a UUID) intoridand the configured timeout intolimitSec. The timeout figure tells you which configuration was live, which helps when a deploy changed it.displayshows just the parsed columns;sortandlimitput the newest 100 first.
Take a rid and run filter @message like "<request-id>" | sort @timestamp asc. The last line the function logged before being stopped is the best clue to what it was waiting on. See filter by request ID.
Variations
Timeouts over time next to total invocations, to tell a spike from a steady trickle:
filter @type = "REPORT" or @message like /Task timed out after/
| stats sum(strcontains(@message, "Task timed out")) as timeouts,
sum(strcontains(@message, "REPORT RequestId")) as invocations
by bin(5m)The dependency that's hanging. Python functions using boto3 log errors such as Read timeout on endpoint URL or Connect timeout on endpoint URL when an AWS API call doesn't respond in time. A connect timeout usually means no network path (a VPC function without a NAT gateway or VPC endpoint); a read timeout means the service accepted the connection but answered slowly:
filter @message like /(Read|Connect) timeout on endpoint URL/
| parse @message /(?<kind>Read|Connect) timeout on endpoint URL: "(?<endpoint>[^"]+)"/
| stats count(*) as n by kind, endpoint
| sort n descAcross all functions: select several /aws/lambda/ log groups and add | stats count(*) as timeouts by @log after the filter.
JSON log format. If the function uses the JSON log format, the report arrives as a platform.report event; filter on record.status = "timeout" instead of the text match.
Timeouts upstream of Lambda
A Lambda timeout is often discovered from the caller's side. API Gateway REST APIs give up on an integration after 29 seconds by default and return a 504 to the client while the function may keep running; HTTP APIs allow up to 30 seconds. At the time of writing, AWS lets you request a longer integration timeout for Regional and private REST APIs through Service Quotas, at the cost of lower throttle limits. If you see 504s in API Gateway logs with no matching Lambda timeout, the function may be finishing after the gateway stopped waiting; compare @duration with 29,000 ms. See API Gateway 504.
Limits and cost
The query scans every event in the selected log groups for the period, so set the range tightly around the incident. Results stop at 10,000 rows; use the stats variation for long periods. For alerting, don't poll this query: alarm on the Errors metric and on Duration approaching the timeout (see the Errors and Duration alarms) and use Logs Insights to investigate.
Questions
How do I find Lambda timeouts in CloudWatch Logs?
Run a Logs Insights query on the function's log group with filter @message like /Task timed out after/. Each match is one timed-out invocation.
What does 'Read timeout on endpoint URL' mean?
An AWS SDK call (commonly boto3) waited too long for a response from that service endpoint. A connect timeout means it couldn't open a connection at all, often a VPC networking issue.
Can API Gateway wait more than 30 seconds for Lambda?
For REST APIs the default limit is 29 seconds; Regional and private REST APIs can request a higher limit through Service Quotas. HTTP APIs are capped at 30 seconds.
Timeouts usually start when a dependency slows down, and that rarely waits for office hours. CloudConsole, a phone app for AWS, is built to show the alarm and the timed-out invocations on your phone.
About the app → · Download on the App Store