This topic describes how to implement instance lifecycle hooks in a Custom Container runtime.
Lifecycle hooks
After you implement and configure lifecycle hooks for function instances, Function Compute calls the corresponding hook when a related instance lifecycle event occurs. Initializer and PreStop hooks can be configured for function instances in Custom Container runtimes. For more information, see Function instance lifecycles.
The following table describes the method to implement the Initializer hook. The method to implement the PreStop hook is the same.
Path | Input request | Expected response |
(Optional) POST | Request body: none. Request header: common request headers. For more information, see Common request headers in Function Compute. | Response body: the return value of Initializer. StatusCode
Sample code of
|
(Optional) GET |
| Response body: the return value of the PreStop hook. StatusCode
|
If you want to use the Initializer hook in a custom runtime, you must implement the corresponding logic with the /initialize
path and the POST
method in your HTTP server. You can use the sample code for initialize
in the preceding table as references.
If you do not configure Initializer when you create a function, you do not need to implement /initialize
. In this case, even if the HTTP Server implements /initialize
, the /initialize
logic in the code cannot be called and executed.