You can route events to Log Service by using the event rule to filter events. This topic describes the prerequisites and procedure for routing custom events to Log Service. This topic also describes how to verify the result.

Step 1: Create a custom event source

  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, set the Name and Description parameters, select Custom Application from the Event Provider drop-down list, and then click OK.

Step 2: Create an event rule

Important The event targets that you want to configure for an event rule must reside in the same region as the event rule.
  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 event bus that you want to manage.
  3. In the left-side navigation pane, click Event Rules. On the page that appears, click Create Rule.
  4. In the Create Rule panel, perform the following steps and click Create:
    1. In the Configure Basic Info step, configure Name and Description and click Next Step.
    2. In the Configure Event Pattern step, set the Event Source Type parameter to Custom Event Source, select the custom event source that is created in Step 1: Create a custom event source from the Event Source drop-down list, specify an event pattern in the Pattern Content code editor, and then click Next Step.

      For more information, see Event patterns.

    3. In the Configure Targets step, set the Service Type parameter to Log Service, and configure the following parameters:
      Note You can configure up to five event targets for an event rule.
      • Log Project: Select the Log Service project that you created.
      • Logstore: Select the Log Service Logstore that you created.
      • Log Topic: Enter a custom log topic.
      • Log Content: Select the log content that you want to route. For more information, see Event transformation.
      • Role: Select the role that you want to authorize. EventBridge can use this role to read the logs in Log Service. The following sample code provides an example on the permission policy for your role. For more information, see Policies.
        {
          "Version":"1",
          "Statement":[
            {
              "Effect":"Allow",
              "Action":[
                "log:PostLogStoreLogs"
              ],
              "Resource":[
                "acs:log:*:*:project/<Project name>/logstore/<Logstore name>"
              ]
            }
          ]
        }

Step 3: Publish an event

  1. Log on to the EventBridge console.
  2. In the left-side navigation pane, click Event Buses.
  3. In the top navigation bar, select a region.
  4. On the Event Buses page, find the event bus to which you want to publish an event and click Publish Event in the Operations column.
    Note You can publish events only to custom event buses in the EventBridge console.
  5. In the Publish Event to Custom Event Bus panel, select a custom event source from the Custom Event Source drop-down list, enter the event content in the Event Body code editor, and then click OK.
    For more information about the event parameters, see Overview.

Verify the result

  1. Log on to the Log Service console.
  2. In the Projects section, click the project that you want to view.
  3. On the Logstores page, click the Logstore that you want to manage.
  4. Click Search & Analyze to view the query and analysis results.
    Query analysis