This topic describes how to implement lifecycle hooks for function instances in a custom container runtime.
Lifecycle hooks
After you configure a lifecycle hook for a function instance, Function Compute invokes the hook when a related lifecycle event for the instance occurs. The following lifecycle hooks can be configured for a function instance: Initializer, PreFreeze, and PreStop hooks. For more information, see Function instance lifecycle.
Path | Request | Expected response |
---|---|---|
(Optional) POST /initialize | Request body: none. Request header: common request headers. For more information, see Common request headers in Function Compute. | Response body: the return value of the Initializer hook. StatusCode
Sample code of initialize in Python:
|
(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 function. StatusCode
|
If you want to use the Initializer hook in a custom runtime, you need to only implement the logic that corresponds to the
/initialize
path and the POST
method in your HTTP server. You can refer to the sample code for initialize
in the preceding table. Important If you do not configure the Initializer hook for the function, the
/initialize
path does not need to be implemented. Even if the /initialize
path is implemented by the HTTP server, you cannot invoke or execute the /initialize
logic in the code. The PreFreeze and PreStop methods are used in the same manner as the Initializer method.