Function's Specification ​
With the Serverless module, you can create Functions in both Node.js and Python. Although the Function's interface is unified, its specification differs depending on the runtime used to run the Function.
Signature ​
Function's code is represented by a handler that is a method that processes events. When your Function is invoked, it runs this handler method to process a given request and return a response.
All Functions have a predefined signature with elements common for all available runtimes:
- Functions' code must be introduced by the
mainhandler name. - Functions must accept two arguments that are passed to the Function handler:
eventcontext
See these signatures for each runtime:
Event Object ​
The event object contains information about the event the Function refers to. For example, an API request event holds the HTTP request object.
Functions in Kyma accept CloudEvents (ce) with the following specification:
See the detailed descriptions of these fields:
| Field | Description |
|---|---|
| ce-type | Type of the CloudEvent data related to the originating occurrence |
| ce-source | Unique context in which an event happened and can relate to an organization or a process |
| ce-eventtypeversion | Version of the CloudEvent type |
| ce-specversion | Version of the CloudEvent specification used for this event |
| ce-id | Unique identifier of the event |
| ce-time | Time at which the event was sent |
| data | Either JSON or a string, depending on the request type. Read more about Buffer in Node.js and bytes literals in Python. |
| tracer | Fully configured OpenTelemetry tracer object that allows you to communicate with the user-defined trace backend service to share tracing data. For more information on how to use the tracer object see Customize Function traces |
| extensions | JSON object that can contain event payload, a Function's incoming request, or an outgoing response |
Event Object SDK ​
The event object is extended by methods making some operations easier. You can use every method by providing event.{FUNCTION_NAME(ARGUMENTS...)}.
Context Object ​
The context object contains information about the Function's invocation, such as runtime details, execution timeout, or memory limits.
See sample context details:
...
{
"function-name": "main",
"timeout": 180,
"runtime": "nodejs20",
"memory-limit": 200Mi
}See the detailed descriptions of these fields:
| Field | Description |
|---|---|
| function-name | Name of the invoked Function |
| timeout | Time, in seconds, after which the system cancels the request to invoke the Function |
| runtime | Environment used to run the Function. You can use nodejs20 or python312. |
| memory-limit | Deprecated: Maximum amount of memory assigned to run a Function |
HTTP Requests ​
You can use the event.extensions.request object to access properties and methods of a given request that vary depending on the runtime. For more information, read the API documentation for Node.js Express and Python.
Custom HTTP Responses ​
By default, a failing Function simply throws an error to tell the Event Service to reinject the event at a later point. Such an HTTP-based Function returns the HTTP status code 500. If you manage to invoke a Function successfully, the system returns the default HTTP status code 200.
Apart from these two default codes, you can define custom responses. Learn how to do that in Node.js and Python:
By default, a failing Function simply throws an error to tell the Event Service to reinject the event at a later point. Such an HTTP-based Function returns the HTTP status code 500. If you manage to invoke a Function successfully, the system returns the default HTTP status code 200.
Apart from these two default codes, you can define custom responses. Learn how to do that in Node.js and Python:
Override Runtime Image ​
You can use a custom runtime image to override the existing one. Your image must meet all the following requirements:
- Expose the workload endpoint on the right port
- Provide liveness and readiness check endpoints at
/healthz - Fetch sources from the path under the
KUBELESS_INSTALL_VOLUMEenvironment - Security support. Kyma runtimes are secure by default. You only need to protect your images.
NOTE
For better understanding, you can look at the main Docker files. They are responsible for building the final image based on the base_image argument. You, as a user, can override it and what we are doing in this tutorial.
Every Function's Pods container has the same system environments, which helps you configure the Functions server. For more information, read the Environment variables page.