Help Center > > Developer Guide> Overview> Supported Event Sources

Supported Event Sources

Updated at: Aug 16, 2019 GMT+08:00

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

SMN

Simple Message Notification (SMN) sends messages to email addresses, phone numbers, or HTTP/HTTPS URLs. After you create a function with an SMN trigger, messages published to a specified topic are passed as a parameter (SMN example event) to invoke the function. Then, the function processes the event, for example, publishing the message to other SMN topics or sending it to other Huawei cloud services. For details, see Using an SMN Trigger.

DMS

Distributed Message Service (DMS) is a message queuing service that enables communication between distributed applications. After you create a function with a DMS trigger, messages automatically polled from a specified queue are passed as a parameter (DMS example event) to invoke the function. For details, see Using a DMS Trigger.

API Gateway

API Gateway is an API hosting service that helps enterprises to build, manage, and deploy APIs at any scale. With API Gateway, your function can be invoked through HTTPS by using a custom REST API with a specified backend. You can map each API operation (such as, GET and PUT) to a specific function. API Gateway invokes the relevant function when an HTTPS request (API Gateway 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, object creation or deletion events. When an image is uploaded to the specified bucket, OBS invokes the function to read the image and create a thumbnail. For details, see Using an OBS Trigger.

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 Stream.

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.

Cloud Eye

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

Example Events

  • SMN example event

    In the following example, the function name is test and the topic name is serverless_Test. subject is the message header, and message is the message body.

    {
        "record": [{
            "event_version": "1.0",
            "smn": {
                "message_attributes": null,
                "subject": "This is the message title of smn trigger",
                "message_id": "a5dbd701d70d4ac2a153e7dd6dd9b601",
                "topic_urn": "urn:smn:cn-north-1:bb8695913bb74682b9ca82a8803b60d8:serverless_Test",
                "type": "notification",
                "message": "This is the message body of smn trigger",
                "timestamp": "2017-11-15T04:02:24Z"
                },
            "event_source": "smn",
            "event_subscription_urn": "urn:fss:cn-north-1:bb8695913bb74682b9ca82a8803b60d8:function:default:obsTrigger-Test1:latest"
        }],
        "functionname": "test",
        "requestId": "7c307f6a-cf68-4e65-8be0-4c77405a1b2c",
        "timestamp": "Wed Nov 15 2017 12:00:00 GMT+0800 (CST)"
    }

  • DMS example event

    In the following example, the function name is test. Messages is the message body, which includes Body and Attributes. The event also includes a queue ID and consumer group ID.

    {
        "Tag": "latest",
        "QueueID": "48d11a53-e498-4964-84a2-aaa56442d5ca",
        "ConsumerGroupID": "g-61d9d290-7dae-4144-9ce7-00b9f159cdbe",
        "Messages": [{
            "Body": "This is dms trigger body",
            "Attributes": {
                "dmstrigger": "dmstrigger",
                "dmstrigger2": "dmstrigger"
            }
        }],
        "functionname": "test",
        "requestId": "57453335-ccf7-4d43-8639-79d108158749",
        "timestamp": "Wed Nov 15 2017 14:26:10 GMT+0800 (CST)"
    }
  • API Gateway example event

    The following is an API Gateway example event.

    {
        "httpMethod": "GET",     //Request method
        "path": "/test/hello",   //Request path
        "pathParameters": {      //Path parameters
            "proxy": "hello"
        },
        "queryStringParameters": { //Query parameters
            "name": "me"
        },
        "headers": {               //Request headers
            "x-stage": "RELEASE",
            "Host": "3f96e175-d5e4-4d4b-ae7e-f6d264e63b23-apigw.cn-north-1.huaweicloud.com",
            "User-Agent": "lua-resty-http/0.10 (Lua) ngx_lua/10008",
            ...
        },
        "body": "...",              //Request body
        "isBase64Encoded":false/true,  //Indicates whether the request body is encoded using Base64.
        "requestContext": {
            "stage": "test",          //Environment alias
            "requestId": "dd4337362c02c7d77299e78781beb4b1",
            "apiId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9"
        },

    }

    The function returns characters strings by using the following structure.

    {
        "isBase64Encoded": true|false,
        "statusCode": httpStatusCode,
        "headers": {"headerName":"headerValue",...},
        "body": "..."
    }
  • DIS example event

    In the following example, the stream name is dis-swtest. This example shows the format of a request received by a function that can be invoked by the DIS trigger.

    {
        "ShardID": "shardId-0000000000",
        "Message": {
            "next_partition_cursor": "eyJnZXRJdGVyYXRvclBhcmFtIjp7InN0cmVhbS1uYW1lIjoiZGlzLXN3dGVzdCIsInBhcnRpdGlvbi1pZCI6InNoYXJkSWQtMDAwMDAwMDAwMCIsImN1cnNvci10eXBlIjoiVFJJTV9IT1JJWk9OIiwic3RhcnRpbmctc2VxdWVuY2UtbnVtYmVyIjoiNCJ9LCJnZW5lcmF0ZVRpbWVzdGFtcCI6MTUwOTYwNjM5MjE5MX0",
            "records": [{
                "partition_key": "shardId_0000000000",
                "data": "PEJ1ZmZlcj48L0J1ZmZlcj4=",
                "sequence_number": "0"
            },
            {
                "partition_key": "shardId_0000000000",
                "data": "PEJ1ZmZlcj48L0J1ZmZlcj4=",
                "sequence_number": "1"
            },
            {
                "partition_key": "shardId_0000000000",
                "data": "PEJ1ZmZlcj48L0J1ZmZlcj4=",
                "sequence_number": "2"
            },
            {
                "partition_key": "shardId_0000000000",
                "data": "PEJ1ZmZlcj48L0J1ZmZlcj4=",
                "sequence_number": "3"
            }],
            "millis_behind_latest": ""
        },
        "Tag": "latest",
        "StreamName": "dis-swtest"
    }
  • Timer example event
    {
      "version": "v1.0",
      "time": "2006-01-02T15:04:05-07:00",  // Local date and time
      "trigger_type": "TIMER",   // Trigger type
      "trigger_name": "Trigger name",
      "user_event": "User-defined event"   //Event configured when you create the timer trigger
    }

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel