Where Lambda errors appear
An execution environment goes through two phases you see errors from. Init loads the runtime, your code and its dependencies and runs everything outside the handler, at most 10 seconds. Invoke runs the handler for one event, at most the function's timeout. What fails where:
| Phase | What fails there |
|---|---|
| Deployment | A package over 50 MB uploaded directly or 250 MB unzipped, code storage, environment variables over 4 KB |
| Start of the process | Runtime.InvalidEntrypoint: no bootstrap, a binary for another architecture, a container ENTRYPOINT Lambda cannot run |
| Init | Runtime.ImportModuleError, Runtime.HandlerNotFound, Runtime.UserCodeSyntaxError, an uncaught exception in the code outside the handler, the Init phase's 10 seconds |
| Invoke | Task timed out, out of memory (signal: killed), a full /tmp, Runtime.ExitError, and every error your code throws |
| Before the function runs | TooManyRequestsException (throttled), a payload over the limit, a KMS key Lambda cannot use to decrypt the environment variables |
A synchronous caller - the console's Test button, aws lambda invoke, API Gateway - gets a function error back with status 200 and the header X-Amz-Function-Error; the body holds errorType and errorMessage. Asynchronous invocations and event sources retry it and send it to a dead-letter queue or failure destination if you set one. Either way the whole story is in the log group /aws/lambda/FUNCTION_NAME: aws logs tail /aws/lambda/FUNCTION_NAME --since 1h prints it.
Read the REPORT line
After every invocation Lambda writes one REPORT line to the log. Paste it with the error - the decoder reads it, and a line whose memory used reached the memory size is an out-of-memory kill even when no error says so.
| Field | What it tells you |
|---|---|
Duration | How long the handler ran. Close to the timeout on every invocation: raise the timeout or find the slow call |
Billed Duration | What you pay for, rounded up to the millisecond |
Memory Size / Max Memory Used | The memory setting and the peak of this environment so far. Equal: the process ran out of memory |
Init Duration | Only on the first invocation of an environment - a cold start - and how long Init took |
Status / Error Type | When the line has them, whether the invocation ended in a timeout or an error, and which |
The limits behind the errors
| Limit | Value | Error when exceeded |
|---|---|---|
| Timeout | 3 seconds by default, 900 at most | Task timed out after N seconds |
| Init phase | 10 seconds, then repeated within the timeout | INIT_REPORT ... Status: timeout |
| Memory | 128 to 10,240 MB (one vCPU at 1,769 MB) | Runtime exited with error: signal: killed |
/tmp | 512 to 10,240 MB | No space left on device |
| Payload | 6 MB request and 6 MB response synchronous, 200 MB streamed, 1 MB asynchronous | RequestEntityTooLargeException |
| Deployment package | 50 MB zipped uploaded directly, 250 MB unzipped with layers, 10 GB container image | Unzipped size must be smaller than 262144000 bytes |
| Concurrency | 1,000 per Region by default, shared by all functions | TooManyRequestsException: Rate Exceeded |
Frequently asked questions
Is the error sent anywhere?
No. It is read in your browser: nothing you paste is uploaded, processed on a server or stored. The page only counts that the decoder was used and which kind of error it recognized, never the text.
Why does it work locally and fail in Lambda?
Lambda runs on Amazon Linux, from the files in your package only, with a read-only file system outside /tmp. A dependency installed globally on your machine, a package compiled for macOS or Windows, a file written next to the code or a call that needs the internet from a VPC without a NAT gateway all work on a laptop and fail there.
Does more memory cost more?
Per millisecond, yes, but memory brings CPU with it: a function that runs twice as fast with twice the memory costs the same. Raising the memory is often the cheapest fix for timeouts as well as out-of-memory errors.
Why does the error say the timeout, not how long the work took?
Lambda stops the invocation when the timeout runs out, so Task timed out after 3.00 seconds only says the function had 3 seconds. Log the time before and after each call to an outside service to find which one is slow.
References
Troubleshoot invocation issues in Lambda
Troubleshoot execution issues in Lambda
Troubleshoot deployment issues in Lambda
Lambda quotas
Understanding the Lambda execution environment lifecycle