When building a custom runtime, Function Compute passes context and execution metadata to your runtime through HTTP request headers. This page describes those headers and the log formats your runtime receives.
Request headers
Function Compute automatically generates a set of common request headers and sends them to your custom runtime on every invocation. Both event functions and HTTP functions receive these headers.
To call other Alibaba Cloud services from your function code, use the temporary credentials in thex-fc-access-key-id,x-fc-access-key-secret, andx-fc-security-tokenheaders. If you are migrating an existing application to Function Compute, you can ignore most of these headers.
| Header | Description | Example |
|---|---|---|
x-fc-request-id | The unique ID for this invocation. | a9e64a3c-1234-5678-abcd-ef0123456789 |
x-fc-access-key-id | The temporary AccessKey ID. Function Compute calls AssumeRole to get this value after you configure a role for the function. | STS.NaXxxx |
x-fc-access-key-secret | The temporary AccessKey secret, obtained the same way as x-fc-access-key-id. | 7jXxxx |
x-fc-security-token | The temporary security token, obtained the same way as x-fc-access-key-id. | CAIS... |
x-fc-function-handler | The handler of the function. In a custom runtime or Custom Container runtime, this value is ignored — set it to any string. | index.handler |
x-fc-function-memory | The maximum memory the function is allowed to use. | 512 |
x-fc-region | The region where the function runs. | cn-hangzhou |
x-fc-account-id | The account ID of the function owner. | 123456789012 |
x-fc-qualifier | The service version or alias specified when invoking the function. For details, see Use versions and aliases to implement canary release. | LATEST or myAlias |
x-fc-version-id | The specific service version specified at invocation. | 1 |
x-fc-function-name | The name of the function. | my-function |
x-fc-service-logproject | The Simple Log Service (SLS) log project configured for the service the function belongs to. | my-log-project |
x-fc-service-logstore | The Simple Log Service Logstore configured for the service the function belongs to. | my-logstore |
x-fc-control-path | The request type. See the table below for valid values. | /invoke |
x-fc-control-path values
| Value | Meaning |
|---|---|
/invoke | An event function invocation. |
/http-invoke | An HTTP function invocation. Function Compute adds common headers containing the request path, body, and original headers, forwards the request to your runtime, then forwards the response headers and body back to the client. |
/initialize | The Initializer hook call. Function Compute sends this request the first time it creates a runtime environment. Like a class constructor, the Initializer hook runs only once in the lifetime of a container. |
x-fc-security-token is not supported in Custom Runtime (Debian 11). To get temporary credentials in that environment, read the ALIBABA_CLOUD_ACCESS_KEY_ID, ALIBABA_CLOUD_ACCESS_KEY_SECRET, and ALIBABA_CLOUD_SECURITY_TOKEN environment variables instead. For details, see Configure environment variables.
Log formats
Application logs (stdout)
Enable the logging feature when creating a Function Compute service. All output written to stdout in your custom runtime is automatically collected in the Simple Log Service Logstore you configure. For setup instructions, see Configure the logging feature.
Execution logs (x-fc-log-result)
This log type applies to runtimes other than custom runtimes and Custom Container runtimes. If the invocation request includes the header x-fc-log-type: Tail, the response includes an x-fc-log-result header containing the function's execution logs. Each log entry is capped at 4 KB. View these logs in the function invocation results in the Function Compute console.
The API for specifying the log level varies by programming language. For language-specific details, see Basics.
What's next
Overview — Custom runtime concepts and architecture
Principles — Cold starts and HTTP server configuration in a custom runtime
Web functions — How to invoke functions in a custom runtime
Lifecycle hooks for function instances — Lifecycle hook implementation in a custom runtime