Help Center/ FunctionGraph/ API Reference/ APIs/ Asynchronous Execution Notification/ Configuring Asynchronous Execution Notification
Updated on 2026-10-27 GMT+08:00

Configuring Asynchronous Execution Notification

Function

This API is used to configure asynchronous execution notification for a function.

Calling Method

For details, see Calling APIs.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions. For details about the required permissions, see Permissions Policies and Supported Actions.

URI

PUT /v2/{project_id}/fgs/functions/{function_urn}/async-invoke-config

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Parameter description:

Project ID. For details, see Obtaining a Project ID.

Constraints:

None

Value range:

32 characters, including letters and digits.

Default value:

None

function_urn

Yes

String

Parameter description:

URN of the function. For details, see Function Model.

Constraints:

None

Value range:

Only letters, digits, underscores (_), hyphens (-), and colons (:) are allowed.

Default value:

None

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Parameter description:

User token.

The token can be obtained by calling the IAM API. The value of X-Subject-Token in the response header is the user token.

Constraints:

None

Value range:

None

Default value:

None

Content-Type

Yes

String

Parameter description:

Specifies the type (or format) of the message body.

Constraints:

None

Value range:

Only application/json is supported.

Default value:

application/json

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

max_async_event_age_in_seconds

No

Integer

Maximum validity period of a message. Value range: 1s to 86,400s. Default value: 3600s.

max_async_retry_attempts

No

Integer

Maximum number of retry attempts to be made if asynchronous invocation fails. Default value: 1. Value range: 0–3.

destination_config

No

FuncAsyncDestinationConfig object

Asynchronous invocation target.

enable_async_status_log

No

Boolean

Whether to enable asynchronous invocation status persistence.

log_group_id

No

String

Log group ID.

log_stream_id

No

String

Log stream ID.

log_group_name

No

String

Log group name.

log_stream_name

No

String

Log stream name.

Table 4 FuncAsyncDestinationConfig

Parameter

Mandatory

Type

Description

on_success

No

FuncDestinationConfig object

Parameter description:

Target to be invoked when a function is successfully executed.

Range:

None

on_failure

No

FuncDestinationConfig object

Parameter description:

Target to be invoked when a function fails to be executed due to a system error or an internal error.

Range:

None

Table 5 FuncDestinationConfig

Parameter

Mandatory

Type

Description

destination

No

String

Parameter description:

Object type.

Range

  • OBS

  • SMN

  • DIS

  • FunctionGraph

param

No

String

Parameter description:

Parameters (in JSON format) corresponding to the target service.

Range

  • OBS: Parameters related to the bucket name, object directory prefix, and object expiration time are included. The object expiration time ranges from 0 to 365 days. If the value is 0, the object will not expire.

  • SMN: The topic_urn parameter is included.

  • DIS: The stream_name parameter is included.

FunctionGraph: The func_urn parameter is included.

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

func_urn

String

Function URN.

max_async_event_age_in_seconds

Integer

Maximum validity period of a message. Value range: 60–86,400. Unit: second.

max_async_retry_attempts

Integer

Maximum number of retry attempts to be made if asynchronous invocation fails. Default value: 3. Value range: 0–8.

destination_config

FuncAsyncDestinationConfig object

Asynchronous invocation target.

created_time

String

Time when asynchronous execution notification was configured.

last_modified

String

Time when the asynchronous execution notification settings were last modified.

enable_async_status_log

Boolean

Whether to enable asynchronous invocation status persistence.

Table 7 FuncAsyncDestinationConfig

Parameter

Type

Description

on_success

FuncDestinationConfig object

Parameter description:

Target to be invoked when a function is successfully executed.

Range:

None

on_failure

FuncDestinationConfig object

Parameter description:

Target to be invoked when a function fails to be executed due to a system error or an internal error.

Range:

None

Table 8 FuncDestinationConfig

Parameter

Type

Description

destination

String

Parameter description:

Object type.

Range

  • OBS

  • SMN

  • DIS

  • FunctionGraph

param

String

Parameter description:

Parameters (in JSON format) corresponding to the target service.

Range

  • OBS: Parameters related to the bucket name, object directory prefix, and object expiration time are included. The object expiration time ranges from 0 to 365 days. If the value is 0, the object will not expire.

  • SMN: The topic_urn parameter is included.

  • DIS: The stream_name parameter is included.

FunctionGraph: The func_urn parameter is included.

Status code: 400

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 404

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

Configure asynchronous execution notification for a function with max. validity period of 10s and max. retries of 3, and enable asynchronous invocation status persistence.

PUT /v2/{project_id}/fgs/functions/{function_urn}/async-invoke-config

{
  "max_async_event_age_in_seconds" : 10,
  "max_async_retry_attempts" : 3,
  "enable_async_status_log" : true
}

Example Responses

Status code: 200

{
  "func_urn" : "urn:fss:xxxxxxxxx:7aad83af3e8d42e99ac194xxxxxxxxxx:function:default:test:latest",
  "max_async_event_age_in_seconds" : 60,
  "max_async_retry_attempts" : 1,
  "destination_config" : {
    "on_success" : {
      "destination" : "FunctionGraph",
      "param" : "{\"func_urn\":\"urn:fss:{region}:5691ba790e2b46ceb38316xxxxxxxxxx:function:default:testPython:latest\"}"
    },
    "on_failure" : {
      "destination" : "FunctionGraph",
      "param" : "{\"func_urn\":\"urn:fss:{region}:5691ba790e2b46ceb38316xxxxxxxxxx:function:default:testPython:latest\"}"
    }
  },
  "created_time" : "2021-03-04T14:50:02+08:00",
  "last_modified" : "2021-03-04 14:50:02",
  "enable_async_status_log" : false
}

SDK Sample Code

The SDK sample code is as follows.

Java

Configure asynchronous execution notification for a function with max. validity period of 10s and max. retries of 3, and enable asynchronous invocation status persistence.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.functiongraph.v2.region.FunctionGraphRegion;
import com.huaweicloud.sdk.functiongraph.v2.*;
import com.huaweicloud.sdk.functiongraph.v2.model.*;


public class UpdateFunctionAsyncInvokeConfigSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        FunctionGraphClient client = FunctionGraphClient.newBuilder()
                .withCredential(auth)
                .withRegion(FunctionGraphRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateFunctionAsyncInvokeConfigRequest request = new UpdateFunctionAsyncInvokeConfigRequest();
        request.withFunctionUrn("{function_urn}");
        UpdateFunctionAsyncInvokeConfigRequestBody body = new UpdateFunctionAsyncInvokeConfigRequestBody();
        body.withEnableAsyncStatusLog(true);
        body.withMaxAsyncRetryAttempts(3);
        body.withMaxAsyncEventAgeInSeconds(10);
        request.withBody(body);
        try {
            UpdateFunctionAsyncInvokeConfigResponse response = client.updateFunctionAsyncInvokeConfig(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Python

Configure asynchronous execution notification for a function with max. validity period of 10s and max. retries of 3, and enable asynchronous invocation status persistence.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkfunctiongraph.v2.region.functiongraph_region import FunctionGraphRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkfunctiongraph.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = FunctionGraphClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(FunctionGraphRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateFunctionAsyncInvokeConfigRequest()
        request.function_urn = "{function_urn}"
        request.body = UpdateFunctionAsyncInvokeConfigRequestBody(
            enable_async_status_log=True,
            max_async_retry_attempts=3,
            max_async_event_age_in_seconds=10
        )
        response = client.update_function_async_invoke_config(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

Configure asynchronous execution notification for a function with max. validity period of 10s and max. retries of 3, and enable asynchronous invocation status persistence.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    functiongraph "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        SafeBuild()

    if err != nil {
        fmt.Println(err)
        return
    }

    hcClient, err := functiongraph.FunctionGraphClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


    if err != nil {
        fmt.Println(err)
        return
    }

    client := functiongraph.NewFunctionGraphClient(hcClient)

    request := &model.UpdateFunctionAsyncInvokeConfigRequest{}
	request.FunctionUrn = "{function_urn}"
	enableAsyncStatusLogUpdateFunctionAsyncInvokeConfigRequestBody:= true
	maxAsyncRetryAttemptsUpdateFunctionAsyncInvokeConfigRequestBody:= int32(3)
	maxAsyncEventAgeInSecondsUpdateFunctionAsyncInvokeConfigRequestBody:= int32(10)
	request.Body = &model.UpdateFunctionAsyncInvokeConfigRequestBody{
		EnableAsyncStatusLog: &enableAsyncStatusLogUpdateFunctionAsyncInvokeConfigRequestBody,
		MaxAsyncRetryAttempts: &maxAsyncRetryAttemptsUpdateFunctionAsyncInvokeConfigRequestBody,
		MaxAsyncEventAgeInSeconds: &maxAsyncEventAgeInSecondsUpdateFunctionAsyncInvokeConfigRequestBody,
	}
	response, err := client.UpdateFunctionAsyncInvokeConfig(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

More

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Ok

400

Bad Request

404

Not Found

Error Codes

See Error Codes.