This topic describes the request parameters, response parameters, judgments, and calls of event functions in a custom runtime.

Background information

In a custom runtime, Function Compute forwards the common headers, request body, POST method, /invoke, and /initialize to the HTTP server. A request parameter similar to the context in an official runtime can be built based on the information in common headers and a request parameter similar to the event in an official runtime can be built based on the request body of the called function. If you do not want to define the event call function as def handler(context, event), you can use this HTTP server directly to implement the business logic.

Input parameters of functions

  • event: the body of the POST request
  • context:
    • The x-fc-access-key-id, x-fc-access-key-secret, and x-fc-security-token headers are used to obtain temporary credentials for the service role to access other Alibaba Cloud services.
    • The x-fc-request-id header is used to obtain the current request ID.
    • For more information about request headers, see Common headers.

Function response structure

The results of a function call are returned as an HTTP response.

Function judgment

In a custom runtime, you can distinguish common calls from HTTP trigger calls based on the value of the x-fc-control-path field in the request header as follows:

  • /Invoke : The request is an event function call. In this case, Function Compute calls a function without using the HTTP trigger.
  • /Initialize : The request is an event function call. Before a function is called for the first time, Function Compute initializes the runtime environment.
  • /HTTP-invoke : The request is an HTTP function call. In this case, Function Compute uses the HTTP trigger to call a function. Function Compute forwards the user request (including the path, specific request header fields, and body) and common request header fields to the HTTP server in the custom runtime. After receiving the response header fields and body from the HTTP server, Function Compute returns the response to the client that makes the call request.

Calls

Path x-fc-control-path Request Expected response
POST /invoke /invoke

Request body: function input (the Payload specified when the function is invoked).

Request header: common request headers

Response body: the return value of the function handler.
  • 200: succeeded.
  • 404: failed.

Responds with x-fc-status in the header.

POST /initialize /initialize

Request body: none.

Request header: common request headers

Response body: No response body is returned when the request is successful.
  • 200: succeeded.
  • 404: failed.

Responds with x-fc-status in the header.