In addition to the standard runtime environments for supported programming languages and versions, to satisfy personalized needs of function implementation in more custom programming languages and versions, SCF also provides the Custom Runtime service, which allows you to customize runtime environments. It can implement custom function runtime by opening up its capabilities, enable you to use any programming language on any version to write functions as needed, and implement global operations in function invocation, such as extension load, security plugin, and monitoring agent. SCF and Custom Runtime respond to and process events over HTTP.
Bootstrap file: fixed executable bootstrap file of Custom Runtime. You need to create an executable file with the same name and implement it with a custom programming language and version. It can be directly processed or start another executable file to initialize and invocate the function runtime.
Function file: function program file developed and implemented with a custom programming language and version.
Library files or executable files dependent on by the runtime: relevant dependent library files or executable files required by the runtime in the custom programming language and version.
The function is published in the form of deployment package, which consists of the following files:
As the deployment package size is limited, if a library file or executable file dependent on by the runtime is large, we recommend you publish the function by binding the deployment package to applicable layers, which involves the following files:
Note:
Before publishing the executable files among the above deployment files to SCF, you should set the file executable permission for them, package the deployment files into a ZIP package, and upload the package directly or through COS.
Custom Runtime divides the function runtime into initialization stage and invocation stage. Initialization is executed only once during the instance cold start, while invocation is the execution process called for every event response.
The start time and execution time vary by programming language and version. The initialization timeout period and execution timeout period configuration items are added to SCF specially for Custom Runtime to manage the runtime lifecycle.
SCF first searches for the executable bootstrap file in the deployment package and performs the following operations based on the search result:
The bootstrap file is executed to start function initialization. You can customize the bootstrap to implement custom operations as needed and directly process it or call another executable file to complete initialization. We recommend you perform the following basic operations during initialization:
/tmp
directory./runtime/init/ready
, which informs SCF that Custom Runtime has been initialized and is ready; otherwise, SCF will keep waiting until the configured initialization timeout period elapses and then end Custom Runtime and return an initialization timeout error. If the notifications are repeated, the first access time will be used as the readiness time. In the function invocation stage, you need to customize event acquisition, function invocation, and result return and loop this process.
/runtime/invocation/next
of the runtime API with HTTP client. The response body contains the event data. If this API is repeatedly accessed during an invocation, the same event data will be returned.Note:
Do not set a timeout period for the GET method of the HTTP client.
/runtime/invocation/response
to push the processing result of the function. The first invocation success will be considered as the final event status, which will be locked by SCF, and the result cannot be changed after push./runtime/invocation/error
to push the error message. The current invocation will end, and the first invocation will be considered as the final event status, which will be locked by SCF, and the result cannot be changed in subsequent pushes.You need to implement Custom Runtime with your custom programming language and version, and Custom Runtime and SCF need to communicate with each other over a standard protocol during processes such as event distribution and result returning. Therefore, SCF provides runtime APIs to meet the interaction needs in the lifecycle of Custom Runtime.
SCF has the following built-in environment variables:
Custom Runtime can access runtime APIs through SCF_RUNTIME_API:SCF_RUNTIME_API_PORT
.
Path | Method | Description |
---|---|---|
/runtime/init/ready | post | Calls the API to mark the ready status after runtime initialization. |
/runtime/invocation/next | get | Gets invocation event. The response header contains the following information
|
/runtime/invocation/response | post | Function processing result. After calling the function processing program, the runtime will push the response from the function to the invocation response API. |
/runtime/invocation/error | post | A function return error will be pushed to the invocation error API to mark the current invocation failure. |
Was this page helpful?