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.
Invoking handler.lambdaHandler (nodejs20.x)
Function 'MyFunction' timed out after 3 secondsCommon 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.
Properties:
Timeout: 30Reuse a warm container
Keep the emulator container warm between invokes so pull and init time do not eat the budget.
sam local start-lambda --warm-containers EAGERHow 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.