Route events to an HTTP endpoint

更新时间: 2026-05-09 04:10:17

Use an event rule to filter and route events to an HTTP endpoint. This topic uses a custom event to describe the prerequisites, procedure, and verification steps.

Prerequisites

Activate EventBridge and grant the required permissions

Step 1: Add a custom event source

  1. Log on to the EventBridge console. In the left navigation pane, click Event Buses.
  2. In the top navigation bar, select a region. On the Event Buses page, click the name of the target custom event bus.
  3. In the left navigation pane, click Event Sources, and then click Add Event Source.
  4. In the Add Custom Event Source panel, enter a Name and Description, select Custom Application for Event Provider, and then click OK.

Step 2: Create an event rule

Important

The event target and the event rule must be in the same region.

  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, and then click Create Rule.

  4. On the Create Rule page, perform the following steps.

    1. In the Configure Basic Info wizard, enter a name in the Name text box and a description in the Description text box, and then click Next Step.

    2. In the Configure Event Pattern wizard, set Event Source Type to Custom Event Sources, for Event Source, select the custom event source that you created in Step 1: Add a custom event source, enter 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 wizard, configure an event target, and then click Create.

      Note

      You can add up to five event targets for an event rule.

      • Service Type: Select HTTP.

      • URL: Enter the URL of the endpoint.

      • Body: Click Complete Event.

        For more information, see Event transformation.

      • Network Type: Select the network type.

        The following network types are supported:

        • Internet

        • VPC: You must also select an existing VPC, vSwitch, and Security Group.

          Important

          The security group must allow traffic from the CIDR block of the vSwitch.

      • Token: You can use a token to verify that requests originate from EventBridge. The token is sent in an HTTP header with the key x-eventbridge-signature-token. Click Show Advanced Options to display this parameter.

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 target event bus and click Publish Event in the Operations column.

    Note

    The EventBridge console supports publishing events to custom event buses only.

  5. In the Publish Event To Custom Event Bus panel, configure the following settings:

    SettingDescription
    Custom Event SourceSelect an existing custom event source from the drop-down list.
    Event BodyEnter the event content.
  6. Click OK.

Verify the results

Receive the event at your HTTP gateway to view its content. The following code provides an example.

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@SpringBootApplication
@Slf4j
public class EventProcessingApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @PostMapping("/eventBridge/processEvent")
    @ResponseBody
    public String receiveMessage(@RequestBody String data) {
        log.info("receiveEvent");
        log.info(data);
        return "received";
    }
}
上一篇: Route events to Simple Message Queue (formerly MNS) 下一篇: Route events to SMS
阿里云首页 事件总线 相关技术圈