My AWS Lambda function returned a "Runtime exited with error: exit status 129" error.
Resolution
Follow these best practices to review the Lambda function code, find the root cause, and troubleshoot the runtime error.
Take the following actions:
- Check the function code for exit codes that explicitly calls syntax such as process.exit(0), exit(), quit(), os.Exit(), and Environment.Exit(). If the function code includes 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 confirm the function's memory. Lambda allocates CPU power in proportion to the amount of memory configured. If the memory consumption reached the configured limit, then increase the amount of memory. 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 resources consumed. For more information, see Determining the appropriate memory setting for a Lambda function.
- If the function connects to backend databases, then too many connections can 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.
- If you try to reuse an idle connection when you invoke a Lambda function, then you get a connection error. To keep a persistent connection, use the keep-alive setting 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" or "Too many files open" errors. These errors occur because you exceeded the file descriptors and threads limit of 1,024. File descriptor and thread limit issues occur when AWS SDK clients or HTTP connections initialize inside the handler. Make sure that you move these connections to global scope so that connections are reused across invocations. File descriptor issues can also occur when files or sockets aren't closed correctly before the function completes. Turn on Lambda Insights enhanced monitoring on the function. Use specialized query syntax such as the fd_use metric to search and analyze log data for memory usage metrics. Lambda Insights stores the metrics in the log group name /aws/lambda-insights. For more information, see Metrics collected by Lambda Insights.