This topic describes the structural features, instance usage, and FAQ of event handlers in a custom runtime.

Background information

In a custom runtime, Function Compute forwards the common headers, the request body, the POST method, the /invoke path, and the /initialize path to your HTTP server. You can build an input parameter similar to the context parameter in an official runtime based on the information in common headers. You can also build an input parameter similar to the event parameter in an official runtime based on the request body of the invoked function. fccustomeruntimeruntime

Function invocation

If the function uses an event handler, the HTTP server needs to only implement the logic that corresponds to the /invoke path and the POST method.

Path Request Expected response
POST /invoke
  • Request body: the function input, which is the payload that you specify when you call the InvokeFunction operation.
  • Request header: common request headers. For more information, see Common request headers in Function Compute.
    Notice Content-Type must be application/octet-stream.
Response body: the return value of the function handler. The return value includes the response code and response header.
  • HTTP status code (StatusCode)
    • 200: succeeded
    • 404: failed
  • Response header (x-fc-status)
    • 200: succeeded
    • 404: failed
You can include the x-fc-status field in response headers to report whether the local function is invoked to Function Compute.
  • If you do not specify a value for the x-fc-status field, Function Compute considers the invocation successful. If an error occurs during function execution, the system does not report the error to Function Compute. In this case, the business logic is not affected, but the observability of Function Compute is affected. The following figure provides an example.image8hanshujisuanruntime
  • If you specify a value for the x-fc-status field, the system reports function invocation failures to Function Compute by using the x-fc-status field. If an error occurs during function invocation, the system records the error stack information in logs. The following figure provides an example.image9runtimefc
Note We recommend that you specify the StatusCode and x-fc-status fields in the HTTP response.

Examples

PHP

Go

Node.js

Python

Ruby

C++

TypeScript

Powershell

Lua

Dart

Rust

FAQ