Invokes a function.
Request headers
This operation uses only common request headers. For more information, see Common parameters.
Parameter | Type | Required | Examples | Description |
---|---|---|---|---|
X-Fc-Invocation-Type | String | No | Sync | The invocation method. Valid values:
|
X-Fc-Log-Type | String | No | None | The method used to return logs. Valid values:
|
X-Fc-Stateful-Async-Invocation-Id | String | No | g6u*****iyvhd3jk8s6bhj0hh | The ID of the asynchronous task. You must enable the asynchronous task feature in advance. Note When you use an SDK to invoke a function, we recommend that you specify a business-related ID to facilitate subsequent operations. For example, you can use the video name as the invocation ID for a video-processing function. After that, you can use the ID to check whether the video is processed or terminate the processing of the video. The ID must start with a letter or an underscore (_), and can contain letters, digits, underscores (_), and hyphens (-). The ID can be up to 128 characters in length. If you do not specify the ID of the asynchronous invocation, Function Compute automatically generates an ID. |
Request syntax
POST /services/{serviceName.qualifier}/functions/{functionName} HTTP/1.1
Request parameters
Parameter | Type | Location | Required | Example | Description |
---|---|---|---|---|---|
serviceName | String | Path | Yes | service_name | The name of the service. |
qualifier | String | Path | No | LATEST | The version or alias of the service. |
functionName | String | Path | Yes | function_name | The name of the function. |
String | Body | Yes | {"key1": "value1"} | The event of the function. The value of this parameter is a binary array. Function Compute passes the event to the function for processing. |
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
X-Fc-Error-Type | String | UnhandledInvocationError | The type of errors returned after the function is invoked. Valid values:
|
X-Fc-Log-Result | String | demo log result | The returned log results. |
X-Fc-Code-Checksum | String | 5697641582914695457 | The CRC-64 value of the function code package. |
X-Fc-Stateful-Async-Invocation-Id | String | g6u*****iyvhd3jk8s6bhj0hh | The ID of the asynchronous task. You must enable the asynchronous task feature in advance. Note When you use an SDK to invoke a function, we recommend that you specify a business-related ID to facilitate subsequent operations. For example, you can use the video name as the invocation ID for a video-processing function. After that, you can use the ID to check whether the video is processed or terminate the processing of the video. The ID must start with a letter or an underscore (_), and can contain letters, digits, underscores (_), and hyphens (-). The ID can be up to 128 characters in length. Function Compute generates an ID for the asynchronous task if it is not specified. |
X-Fc-Instance-Id | String | 7c43576b-48b1-4c3a-86e5-dcb01872**** | The ID of the function instance. |
X-Fc-Request-Id | String | dab25e58-9356-4e3f-97d6-f044c4**** | The request ID of the function invocation. |
X-Fc-Max-Memory-Usage | String | 9.2 | The memory consumed by the function execution. Unit: MB. |
X-Fc-Invocation-Duration | String | 10 | The duration consumed by the function execution, in milliseconds. |
X-Fc-Invocation-Service-Version | String | LATEST | The version or alias of the called function. |
String | hello world | The result returned after the function is invoked. You can specify the result returned. |
Examples
Sample requests
POST /services/{serviceName.qualifier}/functions/function_name HTTP/1.1
Host:fc-ram.aliyuncs.com
X-Fc-Invocation-Type:Sync
X-Fc-Log-Type:None
X-Fc-Stateful-Async-Invocation-Id:g6u*****iyvhd3jk8s6bhj0hh
Content-Type:application/json
{"key1": "value1"}
Sample success responses
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"result" : "hello world"
}