Help Center/ FunctionGraph/ Developer Guide/ Overview/ Supported Event Sources
Updated on 2024-06-06 GMT+08:00

Supported Event Sources

This section describes the cloud services that can be configured as event sources for your FunctionGraph functions. After you preconfigure the event source mapping, these event sources automatically invoke the relevant function when detecting events.

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.

APIG

API Gateway (APIG) is an API hosting service that helps enterprises to build, manage, and deploy APIs at any scale. With APIG, your function can be invoked through HTTPS by using a custom REST API and a specified backend. 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 backend. For details, see Using an APIG Trigger.

OBS

Object Storage Service (OBS) is a stable, secure, efficient, and easy-to-use cloud storage service. You can create a function to process OBS bucket events, for example, creating and deleting objects. When an image is uploaded to a specified bucket, OBS invokes the function to read the image and create a thumbnail. For details, see Using an OBS Trigger.

Table 1 Event types supported by OBS

Event

Description

ObjectCreated

All kinds of object creation operations, including PUT, POST, and COPY of objects, as well as the merging of parts.

Put

Use the PUT method to upload objects.

Post

Use the POST method to upload objects.

Copy

Use the COPY method to replicate objects.

CompleteMultipartUpload

Merge parts of multi-part tasks.

ObjectRemoved

Delete objects.

Delete

Delete objects by versions.

DeleteMarkerCreated

Delete objects without specifying versions.

Multiple event types can be used on the same object. For example, if you have selected Put, Copy, and Delete in an event notification rule, a notification message will be sent to you when the specified object is uploaded to, copied to, or deleted from the bucket. ObjectCreated contains Put, Post, Copy, and CompleteMultipartUpload. If you select ObjectCreated, the others are automatically selected and cannot be selected again. Similarly, if you select ObjectRemoved, Delete and DeleteMarkerCreated are automatically selected and cannot be selected again.

DIS

Data Ingestion Service (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 location-tracking events (DIS example event). FunctionGraph periodically polls the stream for new data records. For details, see Using a DIS Trigger.

Timer

You can schedule a timer (timer example event) to invoke your code based on a fixed rate of minutes, hours, or days or a cron expression. For details, see Using a Timer Trigger.

DMS for Kafka

DMS for Kafka is a message queuing service that provides Kafka premium instances. If you create a Kafka trigger for a function, when a message is sent to a Kafka instance topic, FunctionGraph will retrieve the message and trigger the function to perform other operations. For details, see Using a Kafka Trigger.

Cloud Eye

Cloud Eye is a multi-dimensional resource monitoring platform. FunctionGraph is interconnected with Cloud Eye to report metrics, allowing you to view function metrics and alarm messages through Cloud Eye. For more information about metrics, see Viewing Function Metrics.

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.

Example Events

  • SMN example event
    {
        "record": [
            {
                "event_version": "1.0",
                "smn": {
                    "topic_urn": "urn:smn:{region}:0162c0f220284698b77a3d264376343a:{function_name}",
                    "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": "urn:fss:{region}:0162c0f220284698b77a3d264376343a:function:default:read-smn-message:latest",
                "event_source": "smn"
            }
    ],
        "functionname": "test",
        "requestId": "7c307f6a-cf68-4e65-8be0-4c77405a1b2c",
        "timestamp": "Wed Nov 15 2017 12:00:00 GMT+0800 (CST)"
    }
    Table 2 Parameter description

    Parameter

    Type

    Example Value

    Description

    event_version

    String

    1.0

    Event version

    topic_urn

    String

    See the example.

    ID of an SMN event

    type

    String

    notification

    Event type

    RequestID

    String

    7c307f6a-cf68-4e65-8be0-4c77405a1b2c

    Request ID. The ID of each request is unique.

    message_id

    String

    a51671f77d4a479cacb09e2cd591a983

    Message ID. The ID of each message is unique.

    Message

    String

    this is smn message content

    Message content

    event_source

    String

    smn

    Event source

    event_subscription_urn

    String

    See the example.

    Subscription ID

    timestamp

    String

    Wed Nov 15 2017 12:00:00 GMT+0800 (CST)

    Time when an event occurs

  • OBS example event
    {
        "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 3 Parameter description

    Parameter

    Type

    Example Value

    Description

    eventVersion

    String

    2.0

    Event version

    eventTime

    String

    2018-01-09T07:50:50.028Z

    Time when an event occurs. The ISO-8601 time format is used.

    sourceIPAddress

    String

    103.218.216.125

    Source IP address

    s3

    Map

    See the example.

    OBS event content

    object

    Map

    See the example.

    object parameter description

    bucket

    Map

    See the example.

    bucket parameter description

    arn

    String

    arn:aws:s3:::syj-input2

    Bucket ID

    ownerIdentity

    Map

    See the example.

    ID of the user who creates the bucket

    Region

    String

    ap-southeast-3

    Region where the bucket is located

    eventName

    String

    ObjectCreated:Post

    Event name

    userIdentity

    Map

    See the example.

    ID of the Huawei Cloud account that initiates the request

  • APIG example event
    {
        "body": "{\"test\":\"body\"}",
        "requestContext": {
            "apiId": "bc1dcffd-aa35-474d-897c-d53425a4c08e",
            "requestId": "11cdcdcf33949dc6d722640a13091c77",
            "stage": "RELEASE"
        },
        "queryStringParameters": {
            "responseType": "html"
        },
        "httpMethod": "GET",
    "pathParameters": {
    "path":"value"
    },
        "headers": {
            "accept-language": "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
    }
    • 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": "..."
      }
    Table 4 Parameter description

    Parameter

    Type

    Example Value

    Description

    body

    String

    "{\"test\":\"body\"}"

    Actual request in string format

    requestContext

    Map

    See the example.

    Request information, including the API gateway configuration, request ID, authentication information, and source

    httpMethod

    String

    GET

    HTTP method

    queryStringParameters

    Map

    See the example.

    Query strings configured in APIG and their actual values

    pathParameters

    Map

    See the example.

    Path parameters configured in APIG and their actual values

    headers

    Map

    See the example.

    Complete headers

    path

    String

    /apig-event-template

    Complete path

    isBase64Encoded

    Boolean

    True

    Default value: true

  • DIS example event
    {
        "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 5 Parameter description

    Parameter

    Type

    Example Value

    Description

    ShardID

    String

    shardId-0000000000

    Partition ID

    next_partition_cursor

    String

    See the example.

    Next partition cursor

    Records

    Map

    See the example.

    Data records stored in a DIS stream

    partition_key

    String

    See the example.

    Partition key

    data

    String

    See the example.

    Data blocks, which are added by the data producer to the stream

    sequence_number

    Int

    See the example.

    Record ID, which is automatically allocated by DIS

    Tag

    String

    latest

    Stream tag

    StreamName

    String

    dis-swtest

    Stream name

  • Timer example event
    {
        "version": "v1.0",
        "time": "2018-06-01T08:30:00+08:00",
        "trigger_type": "TIMER",
        "trigger_name": "Timer_001",
        "user_event": "User Event"
    }
    Table 6 Parameter description

    Parameter

    Type

    Example Value

    Description

    version

    String

    V1.0

    Event version

    time

    String

    2018-06-01T08:30:00+08:00

    Time when an event occurs.

    trigger_type

    String

    TIMER

    Trigger type

    trigger_name

    String

    Timer_001

    Trigger name

    user_event

    String

    User Event

    Additional information of the trigger

  • Kafka example event
    {
        "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 Parameter description

    Parameter

    Type

    Example Value

    Description

    event_version

    String

    v1.0

    Event version

    event_time

    String

    2018-01-09T07:50:50.028Z

    Time when an event occurs

    trigger_type

    String

    KAFKA

    Event type

    region

    String

    ap-southeast-3

    Region where a Kafka instance resides

    instance_id

    String

    81335d56-b9fe-4679-ba95-7030949cc76b

    Kafka instance ID

    messages

    String

    See the example.

    Message content

    topic_id

    String

    topic-test

    Message ID

  • GeminiDB example event
    {
        "records": [
            {
                "event_name": "\"insert\"",
                "event_version": "1.0",
                "event_source": "gemini_mongo",
                "region": "{region}",
                "gemini_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 8 Parameter description

    Parameter

    Type

    Example Value

    Description

    region

    String

    ap-southeast-3

    Region where a GeminiDB instance resides

    event_source

    String

    gemini_mongo

    Event source

    event_version

    String

    1.0

    Event version

    full_document

    String

    See the example.

    Complete file information

    size_bytes

    Int

    100

    Message bytes

    token

    String

    See the example.

    Base64-encoded data

    vernier

    String

    See the example.

    Cursor

  • RabbitMQ example event
    {
        "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 9 Parameter description

    Parameter

    Type

    Example Value

    Description

    event_version

    String

    v1.0

    Event version

    Region

    String

    ap-southeast-3

    Region where a RabbitMQ instance resides

    instance_id

    String

    81335d56-b9fe-4679-ba95-7030949cc76b

    RabbitMQ instance ID