Skip to content
Latchkey

AWS Lambda "Task timed out after N seconds" in CI

The Lambda runtime killed the invocation because the handler ran past the configured Timeout. In a CI integration test this often means a downstream call hung, or an async handler never resolved its promise.

What this error means

The invoke response is an error and the logs end with "Task timed out after 3.00 seconds". No handler exception is thrown; the runtime simply stops the execution at the limit.

lambda
2026-06-30T12:00:03.512Z 1a2b3c4d Task timed out after 3.00 seconds

END RequestId: 1a2b3c4d
REPORT RequestId: 1a2b3c4d Duration: 3003.11 ms Billed Duration: 3000 ms

Common causes

A downstream call blocks past the timeout

The handler waits on a network call (DB, HTTP, another AWS API) that is slow or unreachable in the CI environment, exceeding the function Timeout.

An async handler never settles

The handler returns a promise that never resolves (a missing callback, an unawaited task, or an open connection), so the runtime waits until the timeout.

How to fix it

Raise the timeout for the integration test

If the work legitimately takes longer, set a realistic Timeout for the function under test.

template.yaml
Properties:
  Timeout: 30

Make the handler resolve deterministically

  1. Ensure every async path is awaited and the handler returns or resolves.
  2. Add a client-side timeout to downstream calls so they fail fast instead of hanging.
  3. Mock slow external dependencies in the CI invoke.
handler.mjs
const res = await fetch(url, { signal: AbortSignal.timeout(2000) });

How to prevent it

  • Set per-call timeouts on downstream requests below the function timeout.
  • Always await async work so the promise settles.
  • Stub external services in CI so latency is bounded.

Frequently asked questions

What causes ""Task timed out after N seconds""?
The handler waits on a network call (DB, HTTP, another AWS API) that is slow or unreachable in the CI environment, exceeding the function Timeout.
How do I fix "Task timed out after N seconds"?
If the work legitimately takes longer, set a realistic Timeout for the function under test.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card