Skip to content
Latchkey

SAM local "Function ... timed out after N seconds" in CI

The local Lambda emulator enforces the same Timeout as the deployed function. When the emulated handler runs longer than that, sam local reports the function timed out and returns no result.

What this error means

sam local invoke or start-api fails with "Function 'MyFunction' timed out after 3 seconds". Cold starts and Docker image pulls can push the first invoke over a short timeout.

sam
Invoking handler.lambdaHandler (nodejs20.x)
Function 'MyFunction' timed out after 3 seconds

Common causes

The template Timeout is too short locally

A 3-second Timeout that works warm in the cloud is exceeded locally when the container cold-starts or the machine is slow.

A downstream call blocks in the local run

The handler calls a service that is slow or unreachable from the runner, so the invoke runs to the timeout.

How to fix it

Raise the timeout for local invokes

Increase the function Timeout, or override warm-container behavior so cold start does not count against a tiny limit.

template.yaml
Properties:
  Timeout: 30

Reuse a warm container

Keep the emulator container warm between invokes so pull and init time do not eat the budget.

Terminal
sam local start-lambda --warm-containers EAGER

How to prevent it

  • Set a realistic Timeout that tolerates local cold starts.
  • Use warm containers for repeated local invokes.
  • Mock slow downstream services in local integration tests.

Frequently asked questions

What causes ""Function 'X' timed out after N seconds""?
A 3-second Timeout that works warm in the cloud is exceeded locally when the container cold-starts or the machine is slow.
How do I fix "Function 'X' timed out after N seconds"?
Increase the function Timeout, or override warm-container behavior so cold start does not count against a tiny limit.

Related guides

References

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