This topic describes the contex-related concepts when you use the Node.js runtime in Function Compute for coding.
What is a context?
When Function Compute runs a function, the system passes a context object to the method that is used to execute the function. The context object contains information about invocations, services, functions, tracing analysis, and runtimes.
The following table describes the parameters that are contained in a context.
Field | Type | Description |
requestId | String | The unique ID of the request that is used to invoke the function. You can record the ID for troubleshooting if an error occurs. |
credentials | Credentials structure, which consists of the following fields:
| The temporary AccessKey pair that Function Compute obtains by assuming your service-linked role. The temporary AccessKey pair is valid for 36 hours. You can use |
function | FunctionMeta structure, which contains the following fields:
| The basic information about the invoked function, such as the name, handler, memory, and timeout period of the function. |
service | ServiceMeta structure, which contains the following fields:
| The information about the service to which the function belongs, such as the name, the related project, and Logstore in Simple Log Service, the version, and the alias of the service. The |
region | String | The ID of the region in which the function is invoked. For example, if the function is invoked in the China (Shanghai) region, the region ID is cn-shanghai. For more information, see Service endpoints. |
accountId | String | The ID of the Alibaba Cloud account to which the function belongs. |
logger | ContextLog structure defined by Function Compute. The structure consists of the following fields:
| Specifies the log object, which is used to print logs. The logs are printed in the Date Request ID [Level] Log content format. Example: 2022-04-01T10:04:19.024Z 19b394a3-4fff-480c-9b5c-cbdfd6952f4e [info] hello,fc. |