This topic describes how to create a custom event source of the Log Service type in the EventBridge console.

Procedure

  1. Log on to the EventBridge console. In the left-side navigation pane, click Event Buses.
  2. In the top navigation bar, select a region. On the Event Buses page, click the name of the custom event bus that you want to manage.
  3. In the left-side navigation pane, click Event Sources, and then click Add Event Source.
  4. In the Add Custom Event Source panel, enter a name in the Name field and a description in the Description field, select Log Service from the Event Provider drop-down list, set the following parameters, and then click OK:
    • Log Project: Select the Log Service project that you created.
    • Logstore: Select the Log Service Logstore that you created.
    • Starting Consumer Offset: Select Earliest Offset, Latest Offset, or Specify Time as the starting offset for consumption.
    • Role: Select the role that you want to authorize. EventBridge can use this role to read the logs in Log Service.
      • When EventBridge uses the role that you provide to read the logs in Log Service, the system creates a consumer group whose name starts with eventbridge- in the Log Service Logstore. After the task is released, the consumer group is also removed.
      • You must ensure that the role that you provide is granted the permissions to read the logs, add consumer groups, and remove consumer groups in the Log Service Logstore. The following code provides an example about permission policies. For more information, see Policies.
        {
          "Version": "1",
          "Statement": [
            {
              "Action": [
                "log:ListShards",
                "log:GetCursorOrData",
                "log:GetConsumerGroupCheckPoint",
                "log:UpdateConsumerGroup",
                "log:ConsumerGroupHeartBeat",
                "log:ConsumerGroupUpdateCheckPoint",
                "log:ListConsumerGroup",
                "log:CreateConsumerGroup",
                "log:DeleteConsumerGroup"
              ],
              "Resource": [
                "acs:log:*:*:project/<Project name>/logstore/<Logstore name>",
                "acs:log:*:*:project/<Project name>/logstore/<Logstore name>/*"
              ],
              "Effect": "Allow"
            }
          ]
        }

Sample event

{
    "datacontenttype": "application/json;charset=utf-8",
    "aliyunaccountid": "175299981560****",
    "data": {
        "key1": "value1",
        "key2": "value2",
        "__topic__": "test_topic",
        "__source__": "test_source",
        "__client_ip__": "122.231.XX.XX",
        "__receive_time__": "1663487595",
        "__pack_id__": "59b662b2257796****"
    },
    "subject": "acs:log:cn-qingdao:175299981560****:project/qiingdaoproject/logstore/qingdao-logstore-1",
    "aliyunoriginalaccountid": "175299981560****",
    "source": "test-SLS",
    "type": "sls:connector",
    "aliyunpublishtime": "2022-09-18T07:53:15.387Z",
    "specversion": "1.0",
    "aliyuneventbusname": "qingdaoBus",
    "id": "qiingdaoproject-qingdao-logstore-1-1-MTY2MzExODM5ODY4NjAxOTQyMw****",
    "time": "2022-09-18T07:53:12Z",
    "aliyunregionid": "cn-qingdao",
    "aliyunpublishaddr": "10.50.XX.XX"
}

For more information about the parameters defined in the CloudEvents specification, see Overview.

The following table describes the parameters contained in data. The parameters that are prefixed and suffixed with an underscore (_) are the system fields of Log Service. For more information about system fields, see Reserved fields.

Parameter Type Example Description
key1 String testKey The field in the log of the user.
__topic__ String testTopic The topic of the log.
__source__ String testSource The device from which the log is collected.
__client_ip__ String 122.231.XX.XX The IP address of the host where the log resides.
__receive_time__ String 1663487595 The time when the log arrives at the server.
__pack_id__ String 59b662b2257796**** The unique ID of the log group to which the log belongs.