Custom Container runtimes receive context information from Function Compute through HTTP request headers. All output written to stdout is automatically collected as logs in Simple Log Service (SLS).
Common request headers
Function Compute automatically injects the following headers into every request it sends to a Custom Container runtime. Both event functions and HTTP functions receive these headers. Use the credential headers to access other Alibaba Cloud services, or read the metadata headers to inspect invocation context at runtime.
If you are migrating an existing application to Function Compute and do not need this context, ignore these headers.
Common request headers are automatically generated by Function Compute. These headers contain permission information and basic information about a function.
To access credentials viax-fc-access-key-id,x-fc-access-key-secret, andx-fc-security-token, first configure a role for your function. Function Compute then calls the AssumeRole API to generate temporary credentials and inject them as headers on each invocation.
| Header | Description |
|---|---|
x-fc-request-id | The request ID for this invocation. |
x-fc-access-key-id | The temporary AccessKey ID. Requires a role to be configured for the function. |
x-fc-access-key-secret | The temporary AccessKey secret. Requires a role to be configured for the function. |
x-fc-security-token | The temporary security token. Requires a role to be configured for the function. |
x-fc-function-handler | The handler configured for the function. For Custom Container functions, this value is ignored and can be any string. |
x-fc-function-memory | The maximum memory the function is allowed to use. |
x-fc-region | The region where the function runs. |
x-fc-account-id | The user ID (UID) of the function owner. |
x-fc-qualifier | The service version or alias specified when invoking the function. See Use versions and aliases to implement canary release. |
x-fc-version-id | The service version that you specify when you invoke a function. |
x-fc-function-name | The function name. |
x-fc-service-logproject | The Simple Log Service project configured for the service. |
x-fc-service-logstore | The Simple Log Service Logstore configured for the service. |
x-fc-control-path | The invocation type. See the values below. |
x-fc-control-path values
| Value | Meaning |
|---|---|
/invoke | An event function invocation. |
/http-invoke | An HTTP function invocation. Function Compute adds the common request headers to the original request (preserving its path, body, and headers) and forwards it to the runtime. The runtime's response headers and body are forwarded back to the client. |
/initialize | The Initializer hook call. Function Compute sends this request automatically the first time it creates a runtime environment for the function. Like a class constructor, the Initializer hook runs only once per container lifecycle. |
Log format
All output written to stdout in a Custom Container runtime is automatically collected in the Simple Log Service Logstore configured for the service. We recommend that you configure the logging feature when you create the service.
Inline log retrieval (non-custom runtimes)
For runtimes other than custom runtimes and Custom Container runtimes, set the x-fc-log-type: Tail request header to retrieve execution logs inline in the response. When this header is set, the response includes the x-fc-log-result header containing the function execution logs. Each log entry is limited to 4 KB. View logs in the Function Compute console.
The API for setting the log level varies by programming language. For details, see Basics.
What's next
To reduce cold start latency caused by container image download and decompression, see Best practices for cold start optimization.
To create a function in a Custom Container runtime, see Create a Custom Container function.
To implement lifecycle hooks for function instances in a Custom Container runtime, see Lifecycle hooks for function instances.