Invokes a function.

Request headers

This operation uses only common request headers. For more information, see Common parameters.

ParameterTypeRequiredExamplesDescription
X-Fc-Invocation-TypeStringNoSync

The invocation method. Valid values:

  • Sync: synchronous invocation
  • Async: asynchronous invocation
X-Fc-Log-TypeStringNoNone

The method used to return logs. Valid values:

  • Tail: returns the last 4 KB of logs that are generated for the current request.
  • None: No logs are returned for the current request. Default value: None.
X-Fc-Stateful-Async-Invocation-IdStringNog6u*****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

ParameterTypeLocationRequiredExampleDescription
serviceNameStringPathYesservice_name

The name of the service.

qualifierStringPathNoLATEST

The version or alias of the service.

functionNameStringPathYesfunction_name

The name of the function.

StringBodyYes{"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

ParameterTypeExampleDescription
X-Fc-Error-TypeStringUnhandledInvocationError

The type of errors returned after the function is invoked. Valid values:

  • HandledInvocationError: errors returned when a callback function is executed in Node.js. For more information, see Error handling.
  • UnhandledInvocationError: all errors except those of the HandledInvocationError type. For more information, see Error handling.
X-Fc-Log-ResultStringdemo log result

The returned log results.

X-Fc-Code-ChecksumString5697641582914695457

The CRC-64 value of the function code package.

X-Fc-Stateful-Async-Invocation-IdStringg6u*****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-IdString7c43576b-48b1-4c3a-86e5-dcb01872****

The ID of the function instance.

X-Fc-Request-IdStringdab25e58-9356-4e3f-97d6-f044c4****

The request ID of the function invocation.

X-Fc-Max-Memory-UsageString9.2

The memory consumed by the function execution. Unit: MB.

X-Fc-Invocation-DurationString10

The duration consumed by the function execution, in milliseconds.

X-Fc-Invocation-Service-VersionStringLATEST

The version or alias of the called function.

Stringhello 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"
}