Invokes a function.

Request headers

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

Parameter Type Required Example Description
X-Fc-Invocation-Type String No Sync

The method used to invoke the function. Valid values:

  • Sync: synchronous
  • Async: asynchronous
X-Fc-Log-Type String No None

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-Id String No g6u*****iyvhd3jk8s6bhj0hh

The ID of the stateful asynchronous invocation.

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, a function that processes a video can use the file name of the video as the invocation ID. Then, you can use this 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 Position Required Example Description
serviceName String Path Yes service_name

The name of the service.

qualifier String Path No test

The version or alias of the service.

functionName String Path Yes function_name

The name of the function.

String Body Yes event

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:

  • HandledInvocationError: errors returned when a callback function is executed in Node.js. For more information, see the "Handle errors" section of the Terms topic.
  • UnhandledInvocationError: all errors except those of the HandledInvocationError type. For more information, see the "Handle errors" section of the Terms topic.
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 stateful asynchronous invocation.

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, a function that processes a video can use the file name of the video as the invocation ID. Then, you can use this 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.
String hello world

The result returned after the function is invoked. You can specify the result returned.

Examples

Sample requests

POST /services/service_name.test/functions/function_name HTTP/1.1 
Common request headers
 {
   "X-Fc-Invocation-Type":"Sync"
   "X-Fc-Log-Type":"None"
   "X-Fc-Stateful-Async-Invocation-Id":"g6u*****iyvhd3jk8s6bhj0hh"
   "Content-Type":"application/json"
   "body":"event"
}

Sample success responses

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "result" : "hello world"
}