This topic explains how to implement lifecycle hooks for function instances within a custom runtime environment.
Callback methods
Once you have implemented and configured lifecycle hooks for function instances, Function Compute will call the appropriate hook when a corresponding instance lifecycle event takes place. You can configure the following lifecycle hooks for a function instance: Initializer, PreFreeze, and PreStop hooks. For more information, see function instance lifecycle hooks.
Path | Input request | Expected response |
(Optional) POST /initialize | Request body: none. Request header: common request headers. For more information, see Function Compute common request headers. | Response body: the return value of the Initializer function. StatusCode
The following is an example code of initialize in Python language:
The following is an example code of function execution error in Python language:
|
(Optional) GET /pre-freeze |
| Response body: the return value of the PreFreeze hook. StatusCode
|
(Optional) GET /pre-stop |
| Response body: the return value of the PreStop hook. StatusCode
|
To utilize the Initializer hook method in a custom runtime, simply implement the required logic at the path
/initialize
with the POST
method on your HTTP server. Refer to the example code of initialize
in the table above for guidance.Important If the function you create does not specify an Initializer, there is no need to implement
/initialize
. Without setting an Initializer, the HTTP server's implementation of /initialize
will not be called or executed./initialize
The PreFreeze and PreStop hook methods are implemented in the same way as the Initializer hook method.
Error codes
Error code ID | Description |
400 |
|
404 | |
500 | Function Compute restarts the instance. |