Introduction
Triggers are key mechanisms in FunctionGraph for initiating function execution. When other cloud services detect specific events as event sources, triggers automatically invoke the associated function based on predefined rules, enabling real-time event processing. For supported trigger events, see Supported Trigger Events.
When events reach the function, they contain only event data relevant to that trigger. This structured JSON data is converted by FunctionGraph into objects usable by the function. A single function can be configured with one or multiple triggers according to service needs. Each trigger can independently invoke the function.
Function Trigger Invocation Mode
Triggers can be invoked synchronously or asynchronously. For details about function invocation, see Invoking the Function.
- Synchronous invocation: After a client invokes a function, FunctionGraph executes the function immediately and returns a response and execution result to the client.
- Asynchronous invocation: After a client invokes a function, FunctionGraph queues the requests and directly returns responses to the client without waiting for the function execution result. FunctionGraph processes the queued requests one by one when the server is idle.
Table 1 Function trigger invocation
Trigger |
Invocation Mode |
API Gateway (dedicated) |
Synchronous. You can change it to asynchronous. For details, see Configuring Asynchronous Invocation. |
API Connect (APIC) |
Synchronous. You can change it to asynchronous. For details, see Configuring Asynchronous Invocation. |
Timer |
Synchronous (default and cannot be changed) |
Cloud Trace Service (CTS) |
Asynchronous (default and cannot be changed) |
Document Database Service (DDS) |
Asynchronous (default and cannot be changed) |
Data Ingestion Service (DIS) |
Asynchronous (default and cannot be changed) |
DMS (for Kafka) |
Asynchronous (default and cannot be changed) |
Kafka (Open-Source) |
Asynchronous (default and cannot be changed) |
DMS (for RabbitMQ) |
Asynchronous (default and cannot be changed) |
GeminiDB Mongo |
Asynchronous (default and cannot be changed) |
Log Tank Service (LTS) |
Asynchronous (default and cannot be changed) |
Simple Message Notification (SMN) |
Asynchronous (default and cannot be changed) |
EventGrid (EG) |
Asynchronous (default and cannot be changed) |
Supported Trigger Events
Table 2 lists the supported cloud services and trigger events for FunctionGraph. After an event source trigger is configured, the corresponding function is automatically invoked when an event is detected.
Table 2 Cloud service events supported by FunctionGraph
Cloud Service/Feature |
Trigger Event |
Timer |
You can schedule a timer (timer example event) to invoke function code based on a fixed rate of minutes, hours, or days or a cron expression.
For details, see Using a Timer Trigger. |
APIG |
FunctionGraph functions are invoked over HTTP or HTTPS by defining REST APIs and endpoints on APIG. You can map each API operation (such as, GET and PUT) to a specific function. APIG invokes the relevant function when an HTTPS request (APIG example event) is sent to the API endpoint.
For details, see Using an APIG (Dedicated) Trigger. |
APIC |
With API operations such as GET and PUT mapped to specific functions, APIC can invoke corresponding functions to perform operations when receiving relevant HTTPS or HTTP requests.
For details, see Using an APIC Trigger. |
DIS |
DIS can ingest large amounts of data in real time. You can create a function to automatically poll a DIS stream and process all new data records, such as website click streams, financial transactions, social media streams, IT logs, and data tracking events (DIS example event). FunctionGraph periodically polls the stream for new data records.
For details, see Using a DIS Trigger. |
DMS for Kafka |
When a message is created in a Kafka topic, FunctionGraph consumes the message and triggers the function to perform other operations (Kafka example event)).
For details about how to use Kafka triggers, see:
|
DMS for RabbitMQ |
When a DMS for RabbitMQ trigger is used, FunctionGraph periodically polls for new messages in a specific topic bound to the exchange of a RabbitMQ instance and passes the messages as input parameters to invoke functions (RabbitMQ example event).
For details, see Using a DMS (for RabbitMQ) Trigger. |
GeminiDB Mongo |
If you create a GeminiDB Mongo trigger for a function, any updates (GeminiDB Mongo example event) to the specified database table will trigger the function.
For details about how to use GeminiDB Mongo triggers, see Using a GeminiDB Mongo Trigger. |
IoTDA |
FunctionGraph can use IoTDA trigger to track device properties, message reporting, and status changes as well as analyze, sort out, and measure data flows (IoTDA example event).
For details, see Using an IoTDA Trigger. |
SMN |
Simple Message Notification (SMN) sends messages to email addresses, mobile phones, or HTTP/HTTPS URLs. If you create a function with an SMN trigger, messages published to a specified topic will be passed as a parameter (SMN example event) to invoke the function. Then, the function processes the event, for example, publishing messages to other SMN topics or sending them to other cloud services.
For details, see Using an SMN Trigger. |
OBS |
Create a function for processing OBS events, such as object creation or deletion (OBS example events). When an image is uploaded to a specified bucket, OBS invokes the function to read the image and create a thumbnail.
For details, see:
|
EG |
EventGrid (EG) receives messages from event sources and passes the message payload as a parameter (EG example event) to invoke a function. Then, the function processes the events, for example, sending messages to other cloud services.
EventGrid supports the following event sources:
|
Trigger Event Examples
- TIMER example event. For details about the parameters, see Table 3.
{
"version": "v2.0",
"time": "2023-06-01T08:30:00+08:00",
"trigger_type": "TIMER",
"trigger_name": "Timer_001",
"user_event": "User Event"
}
Table 3 Parameters of a timer example event
Parameter |
Category |
Description |
version |
String |
Event version |
time |
String |
Event occurrence time, in ISO 8601 format |
trigger_type |
String |
Trigger type |
trigger_name |
String |
Trigger name |
user_event |
String |
Additional information of the trigger |
- API Gateway event example. For details about the parameters, see Table 4.
{
"body": "",
"requestContext": {
"apiId": "bc1dcffd-aa35-474d-897c-d53425a4c08e",
"requestId": "11cdcdcf33949dc6d722640a13091c77",
"stage": "RELEASE"
},
"queryStringParameters": {
"responseType": "html"
},
"httpMethod": "GET",
"pathParameters": {},
"headers": {
"accept-language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"accept-encoding": "gzip, deflate, br",
"x-forwarded-port": "443",
"x-forwarded-for": "103.218.216.98",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"upgrade-insecure-requests": "1",
"host": "50eedf92-c9ad-4ac0-827e-d7c11415d4f1.apigw.region.cloud.com",
"x-forwarded-proto": "https",
"pragma": "no-cache",
"cache-control": "no-cache",
"x-real-ip": "103.218.216.98",
"user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0"
},
"path": "/apig-event-template",
"isBase64Encoded": true
}
Table 4 Parameters of an APIG example event
Parameter |
Category |
Description |
body |
String |
Actual request in string format |
requestContext |
Map |
Request information, including the API gateway configuration, request ID, authentication information, and source |
httpMethod |
String |
HTTP method |
queryStringParameters |
Map |
Query strings configured in APIG and their actual values |
pathParameters |
Map |
Path parameters configured in APIG and their actual values |
headers |
Map |
Complete headers |
path |
String |
Complete path |
isBase64Encoded |
Boolean |
The default value is true. |
Constraints:
- When calling a function using APIG, isBase64Encoded is valued true by default, indicating that the request body transferred to FunctionGraph is encoded using Base64 and must be decoded for processing.
- The function must return characters strings by using the following structure.
{
"isBase64Encoded": true|false,
"statusCode": httpStatusCode,
"headers": {"headerName":"headerValue",...},
"body": "..."
}
Cloud Trace Service (CTS)
- DDS example event. For details about the parameters, see Table 5.
{
"records": [
{
"event_source": "dds",
"event_name": "insert",
"region": "region",
"event_version": "1.0",
"dds": {
"size_bytes": "100",
"token": "{\"_data\": \"825D8C2F4D0000001529295A100474039A3412A64BA89041DC952357FB4446645F696400645D8C2F8E5BECCB6CF5370D6A0004\"}",
"full_document": "{\"_id\": {\"$oid\": \"5d8c2f8e5beccb6cf5370d6a\"},\"name\": \"dds\",\"age\": {\"$numberDouble\": \"52.0\"}}",
"ns": "{\"db\": \"functiongraph\",\"coll\": \"person\"}"
},
"event_source_id": "e6065860-f7b8-4cca-80bd-24ef2a3bb748"
}
]
}
Table 5 Parameters of a DDS example event
Parameter |
Category |
Description |
region |
String |
Region where the DDS instance is located |
event_version |
String |
Event version |
event_source |
String |
Event source |
event_name |
String |
Event name |
size_bytes |
Int |
Message bytes |
token |
String |
Base64-encoded data |
full_document |
String |
Complete file information |
ns |
String |
Column name |
event_source_id |
String |
Event source ID |
Data Ingestion Service (DIS)
- DIS example event. For details about the parameters, see Table 6.
{
"ShardID": "shardId-0000000000",
"Message": {
"next_partition_cursor": "eyJnZXRJdGVyYXRvclBhcmFtIjp7InN0cmVhbS1uYW1lIjoiZGlzLXN3dGVzdCIsInBhcnRpdGlvbi1pZCI6InNoYXJkSWQtMDAwMDAwMDAwMCIsImN1cnNvci10eXBlIjoiVFJJTV9IT1JJWk9OIiwic3RhcnRpbmctc2VxdWVuY2UtbnVtYmVyIjoiNCJ9LCJnZW5lcmF0ZVRpbWVzdGFtcCI6MTUwOTYwNjM5MjE5MX0",
"records": [
{
"partition_key": "shardId_0000000000",
"data": "d2VsY29tZQ==",
"sequence_number": "0"
},
{
"partition_key": "shardId_0000000000",
"data": "dXNpbmc=",
"sequence_number": "1"
},
{
"partition_key": "shardId_0000000000",
"data": "RnVuY3Rpb25TdGFnZQ==",
"sequence_number": "2"
},
{
"partition_key": "shardId_0000000000",
"data": "c2VydmljZQ==",
"sequence_number": "3"
}
],
"millis_behind_latest": ""
},
"Tag": "latest",
"StreamName": "dis-swtest"
}
Table 6 Parameters of a DIS example event
Parameter |
Category |
Description |
ShardID |
String |
Partition ID |
next_partition_cursor |
String |
Next partition cursor |
Records |
Map |
Data records stored in a DIS stream |
partition_key |
String |
Partition key |
data |
String |
Data blocks, which are added by the data producer to the stream |
sequence_number |
Int |
Record ID, which is automatically allocated by DIS |
Tag |
String |
Stream tag |
StreamName |
String |
Stream name |
DMS (for Kafka)/Kafka (Open-Source)
- Kafka example event. For details about the parameters, see Table 7.
{
"event_version": "v1.0",
"event_time": 1576737962,
"trigger_type": "KAFKA",
"region": "region",
"instance_id": "81335d56-b9fe-4679-ba95-7030949cc76b",
"records": [
{
"messages": [
"kafka message1",
"kafka message2",
"kafka message3",
"kafka message4",
"kafka message5"
],
"topic_id": "topic-test"
}
]
}
Table 7 Parameters of a Kafka example event
Parameter |
Category |
Description |
event_version |
String |
Event version |
event_time |
String |
Time when an event occurs |
trigger_type |
String |
Event type |
region |
String |
Region where a Kafka instance resides |
instance_id |
String |
Kafka instance ID |
messages |
String |
Message content |
topic_id |
String |
Message ID |
- DMS for RabbitMQ example event. For details about the parameters, see Table 8.
{
"event_version": "v1.0",
"event_time": 1576737962,
"trigger_type": "RABBITMQ",
"region": "region",
"records": [
{
"messages": [
"rabbitmq message1",
"rabbitmq message2",
"rabbitmq message3",
"rabbitmq message4",
"rabbitmq message5"
],
"instance_id": "81335d56-b9fe-4679-ba95-7030949cc76b",
"exchange": "exchange-test"
}
]
}
Table 8 DMS for RabbitMQ parameters
Parameter |
Category |
Description |
event_version |
String |
Event version |
region |
String |
Region where a RabbitMQ instance resides |
instance_id |
String |
RabbitMQ instance ID |
- GeminiDB Mongo example event. For details about the parameters, see Table 9.
{
"records": [
{
"event_name": "\"insert\"",
"event_version": "1.0",
"event_source": "gauss_mongo",
"region": "cn-north-xx",
"gauss_mongo": {
"full_document": "{\"_id\": {\"$oid\":\"5f61de944778db5fcded3f87\"},\"zhangsan\": \"zhangsan\"}",
"ns": "{\"db\": \"zhangsan\",\"coll\": \"zhangsan\"}",
"size_bytes": "100",
"token": "{\"_data\": \"825F61DE940000000129295A1004A2D9AE61206C43A5AF47CAF7C5C00C5946645F696400645F61DE944778DB5FCDED3F870004\"}"
},
"event_source_id": "51153d19-2b7d-402c-9a79-757163258a36"
}
],
"vernier": "{\"_data\": \"825F61DE940000000129295A1004A2D9AE61206C43A5AF47CAF7C5C00C5946645F696400645F61DE944778DB5FCDED3F870004\"}"
}
Table 9 Parameters of a GeminiDB Mongo example event
Parameter |
Category |
Description |
region |
String |
Region where a GeminiDB instance resides |
event_source |
String |
Event source |
event_version |
String |
Event version |
full_document |
String |
Complete file information |
size_bytes |
Int |
Message bytes |
token |
String |
Base64-encoded data |
event_source_id |
String |
Event source ID |
vernier |
String |
Cursor |
- IoTDA example event. For details about the parameters, see Table 10.
{
"resource" : "device",
"event" : "create",
"event_time" : "20240919T011335Z",
"event_time_ms" : "2024-09-19T01:13:35.854Z",
"request_id" : "75127474-1a26-4578-8847-3128d6101954",
"notify_data" : {
"body" : {
"app_id" : "3d40caf3ddfc4e83815b54b50f13aad7",
"app_name" : "DefaultApp_6439vdv2",
"device_id" : "66eb7a0ffa8d9c36870c6892_ttytytytytytyt",
"node_id" : "ttytytytytytyt",
"gateway_id" : "66eb7a0ffa8d9c36870c6892_ttytytytytytyt",
"node_type" : "GATEWAY",
"auth_info" : {
"auth_type" : "SECRET",
"secure_access" : false,
"timeout" : 0
},
"product_id" : "66eb7a0ffa8d9c36870c6892",
"product_name" : "test",
"status" : "INACTIVE",
"create_time" : "20240919T011335Z"
}
}
}
Table 10 Parameters of an IoTDA example event
Parameter |
Category |
Description |
resource |
string |
Data source, which includes device, device property, device message, device message status, device status, batch task, product, and device asynchronous command status and run log. |
event |
string |
Triggering event. |
event_time |
string |
Event triggering time in the character string format. |
event_time_ms |
string |
Event triggering time in datetime format. |
request_id |
string |
Request ID. |
notify_data |
Object. For details, see Table 11. |
Message to push. |
Table 11 NotifyData
Parameter |
Category |
Description |
body |
Object. For details, see Table 12. |
Message content. |
Table 12 NotifyDataBody
Parameter |
Category |
Description |
app_id |
string |
Resource space ID. |
app_name |
string |
Resource space name. |
device_id |
string |
Device ID, used to uniquely identify a device. The value of this parameter is specified during device registration or allocated by the platform. If the value is allocated by the platform, the value is in the format of [product_id]_[node_id].
Maximum length: 256 characters |
node_id |
string |
Device identifier. This parameter is set to the IMEI, MAC address, or serial number.
Maximum length: 64 characters |
gateway_id |
string |
Gateway ID, which is the device ID of the parent device. The gateway ID is the same as the device ID if the device is a directly connected device. If the device is an indirectly connected device, the gateway ID is the device ID of the directly connected device with which it associates. |
node_type |
string |
Device node type. |
product_id |
string |
Unique ID of the product associated with the device. |
product_name |
string |
Name of the product associated with the device. |
status |
string |
Device status.
- ONLINE: The device is online.
- OFFLINE: The device is offline.
- ABNORMAL: The device is abnormal.
- INACTIVE: The device is not activated.
- FREEZED: The device is frozen.
|
create_time |
string |
Time when the device was registered on the platform. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z. |
auth_info |
Object. For details, see Table 13. |
Access authentication information about the device. |
Table 13 AuthInfo
Parameter |
Category |
Description |
auth_type |
string |
Authentication mode. Secret authentication (SECRET) and certificate authentication (CERTIFICATES) are supported. If secret authentication is used, fill in secret. If certificate authentication is used, fill in fingerprint. If auth_type is not set, secret authentication is used by default. |
secure_access |
Boolean |
Whether the device is connected to the platform using a secure protocol. The default value is true.
- true: The device is connected to the platform using a secure protocol.
- false: The device is connected to the platform using an insecure protocol.
|
timeout |
Integer |
Validity period of the device verification code, in seconds. The default value is 0. If the device has not been connected to the platform within the validity period, the platform deletes the registration information of the device. If this parameter is set to 0, the verification code is always valid. The recommended value is 0. Note: This parameter is returned only when timeout is modified in the device registration or modification API.
Minimum value: 0
Maximum value: 2147483647
Default value: 0 |
For details about device messages, see the IoTDA official website. For example, device addition notification.
Simple Message Notification (SMN)
- SMN example event. For details about the parameters, see Table 14.
{
"record": [
{
"event_version": "1.0",
"smn": {
"topic_urn": "topicUrn",
"timestamp": "2018-01-09T07:11:40Z",
"message_attributes": null,
"message": "this is smn message content",
"type": "notification",
"message_id": "a51671f77d4a479cacb09e2cd591a983",
"subject": "this is smn message subject"
},
"event_subscription_urn": "functionUrn",
"event_source": "smn"
}
],
"functionname": "test",
"requestId": "7c307f6a-cf68-4e65-8be0-4c77405a1b2c",
"timestamp": "Tue Jan 09 2018 15:11:40 GMT+0800 (CST)"
}
Table 14 Parameters of an SMN example event
Parameter |
Category |
Description |
event_version |
String |
Event version |
topic_urn |
String |
Unique ID of an SMN event, which is generated by the SMN service |
type |
String |
Event type |
requestId |
String |
Request ID, which is generated by FunctionGraph.
The ID of each request is unique. |
message_id |
String |
Message ID, which is generated by SMN.
The ID of each message is unique. |
message |
String |
Message |
event_source |
String |
Event source |
event_subscription_urn |
String |
Function URN. The value is unique and can be obtained from the function details page. |
timestamp |
String |
Time when an event occurs |
Object Storage Service (OBS)
- OBS example event. For details about the parameters, see Table 15.
{
"Records": [
{
"eventVersion": "2.0",
"eventTime": "2018-01-09T07:50:50.028Z",
"requestParameters": {
"sourceIPAddress": "103.218.216.125"
},
"s3": {
"configurationId": "UK1DGFPYUKUZFHNQ00000160CC0B471D101ED30CE24DF4DB",
"object": {
"eTag": "9d377b10ce778c4938b3c7e2c63a229a",
"sequencer": "00000000160D9E681484D6B4C0000000",
"key": "job.png",
"size": 777835
},
"bucket": {
"arn": "arn:aws:s3:::syj-input2",
"name": "functionstorage-template",
"ownerIdentity": {
"PrincipalId": "0ed1b73473f24134a478962e631651eb"
}
}
},
"Region": "{region}",
"eventName": "ObjectCreated:Post",
"userIdentity": {
"principalId": "9bf43789b1ff4b679040f35cc4f0dc05"
}
}
]
}
Table 15 Parameters of an OBS example event
Parameter |
Category |
Description |
eventVersion |
String |
Event version |
eventTime |
String |
Time when an event occurs.
The ISO-8601 time format is used. |
sourceIPAddress |
String |
Source IP address |
s3 |
Map |
OBS event content |
object |
Map |
object parameter description |
bucket |
Map |
bucket parameter description |
arn |
String |
Bucket ID |
ownerIdentity |
Map |
ID of the user who creates the bucket |
Region |
String |
Region where the bucket is located |
eventName |
String |
Event name |
userIdentity |
Map |
ID of the Huawei Cloud account that initiates the request |
- EG example event. For details about the parameters, see Table 16.
Custom RocketMQ event source
{
"datacontenttype": "application/json",
"data": {
"context": "yyyyy"
},
"subject": "ROCKETMQ:region:domainId/projectId:ROCKETMQ:eventSourceName",
"specversion": "1.0",
"id": "016d5bd3-6231-4e9e-86ef-e451a070d598",
"source": "eventSourceName",
"time": "2023-04-07T11:51:10Z",
"type": "ROCKETMQ:CloudTrace:RocketmqCall"
}
Custom RabbitMQ event source
{
"datacontenttype": "application/json",
"data": {
"context": "yyyyy"
},
"subject": "RABBITMQ:region:domainId/projectId:RABBITMQ:eventSourceName",
"specversion": "1.0",
"id": "016d5bd3-6231-4e9e-86ef-e451a070d598",
"source": "eventSourceName",
"time": "2023-04-07T11:51:10Z",
"type": "RABBITMQ:CloudTrace:RabbitmqCall"
}
OBS application service event source
{
"channel_id":"b65779ed-d9d0-4a6c-b312-c767226964cf",
"description":"",
"name":"subscription-xeak",
"sources":[
{
"id":null,
"name":"HC.OBS.DWR",
"detail":{
"bucket":"eventbucket",
"objectKeyEncode":true
},
"filter":{
"source":[
{
"op":"StringIn",
"values":[
"HC.OBS.DWR"
]
}
],
"type":[
{
"op":"StringIn",
"values":[
"OBS:DWR:ObjectCreated:PUT",
"OBS:DWR:ObjectCreated:POST"
]
}
],
"subject":{
"and":[
{
"op":"StringStartsWith",
"values":[
"/ddd"
]
}
]
},
"data":{
"obs":{
"bucket":{
"name":[
{
"op":"StringIn",
"values":[
"output-your"
]
}
]
}
}
}
},
"provider_type":"OFFICIAL"
}
],
"targets":[
{
"id":null,
"name":"HC.FunctionGraph",
"detail":{
"urn":"urn:fss:cn-north-7:c53626012ba84727b938ca8bf03108ef:function:A-nodejs-lqz:pylog:latest",
"agency_name":"EG_AGENCY"
},
"dead_letter_queue":null,
"provider_type":"OFFICIAL",
"transform":{
"type":"ORIGINAL",
"value":""
}
}
]
}
Table 16 Parameters of an EG example event
Parameter |
Category |
Description |
datacontenttype |
String |
Data type |
data |
Map |
Data |
subject |
String |
Target value |
specversion |
String |
Version |
id |
String |
Unique key |
source |
String |
Event source name |
time |
String |
Subscription time |
type |
String |
Subscription type |