This topic describes how to determine and invoke event functions in a custom runtime.
contextin an official runtime can be built based on the information in common headers and a request parameter similar to the
eventin an official runtime can be built based on the request body of the invoked function.
Determine the type of the invoked function
For a custom runtime, you can determine whether a request is used to invoke an HTTP function or an event function based on the x-fc-control-path header.
- /invoke: The request is used to invoke an event function. /invoke indicates that the request is used to invoke an event function.
- /initialize: The request is automatically initiated by Function Compute to invoke an initializer function when an execution environment is created for the first time. In the lifecycle of a container, the initializer function is invoked only once, which is similar to the class constructor.
- /http-invoke: The request is used to invoke an HTTP function. /http-invoke indicates that the request is used to invoke an HTTP function. Function Compute adds common headers to your request that includes the HTTP method, request path, request body, query parameters, and request headers and forwards the request to the custom runtime. The custom runtime returns the response headers and body to the client.
initializerparameter is not specified when a function is created,
/initializedoes not need to be implemented. In this case, even if
/initializeis implemented by the HTTP server, the
/initializelogic in the code cannot be invoked or executed.
||Response body: the return value of the function handler.
Note In the HTTP response, we recommend that you specify both the StatusCode and x-fc-status fields.
||Response body: the return value of the function