Updated on 2023-10-11 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.

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.

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.

LTS

Log Tank Service (LTS) collects and stores logs, allowing you to query them in real time. If you create a function with an LTS trigger, subscribed logs collected by LTS will be passed as a parameter (LTS example event) to invoke the function. Then, the function processes or analyzes the logs, or loads the logs to other systems. For details, see Using an LTS Trigger.

CTS

Cloud Trace Service (CTS) collects operation records of subscribed cloud resources. If you create a function with a CTS trigger, collected operation records of specified cloud services will be passed as a parameter (CTS example event) to invoke the function. Then, the function analyzes and processes key information in the operation records, automatically recovers system or network modules, or reports alarms to service personnel by SMS or email. Using a CTS 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.

Example Events

  • 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": {
                        
                        "name": "functionstorage-template",
                        "ownerIdentity": {
                            "PrincipalId": "0ed1b73473f24134a478962e631651eb"
                        }
                    }
                },
                "Region": "{region}",
                "eventName": "ObjectCreated:Post",
                "userIdentity": {
                    "principalId": "9bf43789b1ff4b679040f35cc4f0dc05"
                }
            }
        ]
    }
    Table 2 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

    ownerIdentity

    Map

    See the example.

    ID of the user who creates the bucket

    Region

    String

    ap-southeast-4

    Region where the bucket is located

    eventName

    String

    ObjectCreated:Post

    Event name

    userIdentity

    Map

    See the example.

    ID of the 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 3 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

  • 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 4 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

  • LTS example event
    {
        "lts": {
            "data": "ICB7CiAgICAibG9ncyI6W3sKICAgICAgICAgIm1lc3NhZ2UiOiIyMDE4LTA4LTA4LzA4OjA4OjA4IFtXUk5dIFt0ZXN0LmdvOjA4XVRoaXMgaXMgYSB0ZXN0IG1lc3NhZ2UuIiwKICAgICAgICAgInRpbWUiOjE1MzAwMDk2NTMwNTksCiAgICAgICAgICJob3N0X25hbWUiOiJlY3MtdGVzdCIsCiAgICAgICAgICJpcCI6IjE5Mi4xNjguMS4xIiwKICAgICAgICAgInBhdGgiOiJ2YXIvbG9nL3Rlc3QubG9nIiwKICAgICAgICAgImxvZ191aWQiOiI2NjNkNjkzMC03OTJkLTExZTgtOGIwOC0yODZlZDQ4OGNlNzAiLAogICAgICAgICAibGluZV9ubyI6MQogICAgIH1dLAogICAgIm93bmVyIjogIjYyODBlMTcwYmQ5MzRmNjBhNGQ4NTFjZjVjYTA1MTI5IiwKICAgICJsb2dfZ3JvdXBfaWQiOiAiOTdhOWQyODQtNDQ0OC0xMWU4LThmYTQtMjg2ZWQ0ODhjZTcwIiwKICAgICJsb2dfdG9waWNfaWQiOiAiMWE5Njc1YTctNzg0ZC0xMWU4LTlmNzAtMjg2ZWQ0ODhjZTcwIgogfQ=="
        }
    }
    Table 5 Event parameter description

    Parameter

    Type

    Example Value

    Description

    data

    Sting

    See the example.

    Base64-encoded data

  • CTS example event
    {
        "cts": {
            "time": "2018/06/26 08:54:07 GMT+08:00",
            "user": {
                "name": "userName",
                "id": "5b726c4fbfd84821ba866bafaaf56aax",
                "domain": {
                    "name": "domainName",
                    "id": "b2b3853af40448fcb9e40dxj89505ba"
                }
            },
            "request": {},
            "response": {},
            "code": 204,
            "service_type": "vpc",
            "resource_type": "VPC",
            "resource_name": "workflow-2be1",
            "resource_id": "urn:fgs:{region}:2d1d891d93054bbaa69b9e866c0971ac:graph:workflow-2be1",
            "trace_name": "deleteGraph",
            "trace_type": "ConsoleAction",
            "record_time": "2018/06/26 08:54:07 GMT+08:00",
            "trace_id": "69be64a7-0233-11e8-82e4-e5d37911193e",
            "trace_status": "normal"
        }
    }
    Table 6 Parameter description

    Parameter

    Type

    Example Value

    Description

    User

    Map

    See the example.

    Information about the user who initiates the request

    Request

    Map

    See the example.

    Event request

    Response

    Map

    See the example.

    Event response

    Code

    Int

    204

    Response code, for example, 200 and 400

    service_type

    String

    vpc

    Abbreviation of the sender, for example, vpc and ecs

    resource_type

    String

    VPC

    Resource type of the sender, for example, vm and vpn

    resource_name

    String

    workflow-2be1

    Resource name, for example, the name of an ECS

    trace_name

    String

    deleteGraph

    Event name (trace name), for example, startServer and shutDown

    trace_type

    String

    ConsoleAction

    Event type (trace type), for example, ApiCall

    record_time

    string

    2018/06/26 08:54:07 GMT+08:00

    Time when the CTS service receives the trace

    trace_id

    String

    69be64a7-0233-11e8-82e4-e5d37911193e

    Event ID (trace ID)

    trace_status

    String

    normal

    Event status (trace status)

  • 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

      

    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

  • 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 8 Parameter description

    Parameter

    Type

    Example Value

    Description

    event_version

    String

    v1.0

    Event version

    Region

    String

      

    Region where a RabbitMQ instance resides

    instance_id

    String

    81335d56-b9fe-4679-ba95-7030949cc76b

    RabbitMQ instance ID