How can I troubleshoot Lambda function "runtime exited" errors?

2 minute read

My AWS Lambda function returned a "runtime exited" error.

Short description

Lambda runtime errors return a status code similar to the following:

    "errorType": "Runtime.ExitError",
    "errorMessage": "RequestId: 1234aa1b-cd50-6c78-90cd-ce1234ce9950 Error: Runtime exited with error: exit status 129"


Follow these best practices to review the Lambda function code, identify the root cause, and then troubleshoot the runtime error.

  • Check the function code for exit codes that explicitly calls syntax such as process.exit(0), exit(), quit(), os.Exit(), Environment.Exit(), and so on. If the function code contains any of these exit codes, then either remove them or replace them with a valid return statement.
  • Review the Amazon CloudWatch logs for the Lambda function and check the functions memory. Lambda allocates CPU power in proportion to the amount of memory configured. You might need to increase the amount of memory. You can configure the amount of memory allocated to a Lambda function between 128 MB and 10,240 MB. You can also optimize the code to reduce the amount of resources consumed. For more information, see Memory and computing power.
  • If the function is connecting to backend databases, too many connections might occur. To avoid unnecessary connections, initialize database connections outside of the function handler. Subsequent Lambda function invocation requests can reuse these database connections. For more information, see Best practices for working with AWS Lambda functions.
  • Attempts to reuse an idle connection when invoking a Lambda function results in a connection error. To maintain a persistent connection, use the keep-alive directive associated with your runtime. For more information, see Reusing Connections with keep-alive in Node.js.
  • Check to see if the Lambda function has "out of memory" errors due to the file descriptors and threads limit of 1,024. Turn on Lambda Insights enhanced monitoring on the function. You can search and analyze log data for memory usage metrics using a specialized query syntax. For example, you can monitor the fd_use metric. The metrics are stored in the log group name /aws/lambda-insights. For more information, see Metrics collected by Lambda Insights.

Related information

How do I determine if my Lambda function is timing out?

AWS OFFICIALUpdated a year ago