This error indicates the function process terminated before completing a request. The two common causes are incorrect function logic and missing HTTP server keep-alive configuration.
Incorrect function logic
A bug in function code can cause the process to exit prematurely. This often involves downstream database operations. In the following Python example, os._exit(-1) terminates the process before the function returns a response:
# -*- coding: utf-8 -*-
import os
import logging
def handler(event, context):
logger = logging.getLogger()
logger.info('hello world')
os._exit(-1) # Terminates the process immediately
return 'hello world'Add logging with logging.getLogger() and check the function logs. Look for unhandled exceptions and explicit exit calls such as os._exit().
Missing keep-alive in custom runtimes
When using a custom runtime or Custom Container runtime with a function execution timeout under 15 minutes, the HTTP server must have keep-alive enabled. Without keep-alive, the server may close idle connections and cause the process to exit unexpectedly.
Enable the keep-alive mode and set the request timeout period to 24 hours or longer. In Node.js, configure the HTTP server as follows:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200);
res.end('OK');
});
server.timeout = 0;
server.keepAliveTimeout = 0;
server.listen(9000, '0.0.0.0');Ensure the HTTP server meets these requirements:
Listens on
0.0.0.0:CAPortor*:CAPort, not127.0.0.1. The default port is 9000.Starts within 120 seconds.
For the full list of HTTP server requirements, see Requirements on HTTP server configurations.