Route events to an HTTP endpoint
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
Step 1: Add a custom event source
- Log on to the EventBridge console. In the left navigation pane, click Event Buses.
- In the top navigation bar, select a region. On the Event Buses page, click the name of the target custom event bus.
- In the left navigation pane, click Event Sources, and then click Add Event Source.
-
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
The event target and the event rule must be in the same region.
Log on to the EventBridge console. In the left-side navigation pane, click Event Buses.
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.
In the left-side navigation pane, click Event Rules, and then click Create Rule.
On the Create Rule page, perform the following steps.
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.
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.
In the Configure Targets wizard, configure an event target, and then click Create.
NoteYou 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.
ImportantThe 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
Log on to the EventBridge console.
In the left-side navigation pane, click Event Buses.
In the top navigation bar, select a region.
On the Event Buses page, find the target event bus and click Publish Event in the Operations column.
NoteThe EventBridge console supports publishing events to custom event buses only.
In the Publish Event To Custom Event Bus panel, configure the following settings:
Setting Description Custom Event Source Select an existing custom event source from the drop-down list. Event Body Enter the event content. 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";
}
}