Updated on 2022-02-22 GMT+08:00

Implementing Synchronous Function Invocation

Function

This API is used to implement synchronous function invocation.

For synchronous function invocation, clients must wait for explicit responses to their requests from a function. Responses are returned only after function invocation is complete. For details on how to invoke a function, see Test Management.

URI

POST /v2/{project_id}/fgs/functions/{function_urn}/invocations

Table 1 describes the URI parameters.

Table 1 URI parameters

Parameter

Type

Mandatory

Description

project_id

String

Yes

Tenant's project ID.

function_urn

String

Yes

Function URN. See Function Model.

Header: X-Cff-Log-Type. Options: tail (4 KB logs will be returned) and null (no logs will be returned).

Request

Event in JSON format

Parameter

Type

Mandatory

Description

{Customized_key}

Map<String,String>

No

Function execution request body in JSON format.

Response

Table 2 describes the response parameters.

Table 2 Response parameters

Parameter

Type

Description

X-Cff-Function-Log

String

Function execution log encoded using Base64.

X-Cff-Invoke-Summary

JSON

Execution summary.

Body

JSON

Function execution result.

Example of X-Cff-Invoke-Summary:

 {"duration":1.913,"billingDuration":100,"memorySize":128,"memoryUsed":41.51171875}
Table 3 X-Cff-Invoke-Summary parameters

Parameter

Description

duration

Function execution duration (ms).

billingDuration

Billing duration (ms).

memorySize

Configured memory (MB).

memoryUsed

Used memory (MB).

Example

Example request

POST /v2/7aad83af3e8d42e99ac194e8419e2c9b/fgs/functions/urn:fss:xxxxxxxxx:7aad83af3e8d42e99ac194e8419e2c9b:function:default:test:latest/invocations HTTP/1.1 
{ 
"message":"Hello World" 
}

Example response

The format of the response for a successful request is as follows:

HTTP/1.1 200 OK
{"message": "hello world from FunctionStage"}

The format of the response for a failed request is as follows:

HTTP/1.1 404 Not Found
{"error_code":"FSS.0404","error_msg":"Not found the specified resource"}

Status Code

See Status Codes.