Creating rules in Amazon EventBridge
Prerequisites
Before you begin, ensure you have:
-
Access to the Amazon EventBridge console
-
Appropriate IAM permissions to create EventBridge rules
-
Basic understanding of event-driven architectures
Overview
To take action on events received by EventBridge, you can create rules. When an event matches the event pattern defined in your rule, EventBridge sends the event to the specified target.
This topic walks you through creating a rule that EventBridge uses to match events as they are sent to the specified event bus.
Creating EventBridge rules involves four main steps:
-
Choose the events you want to process
-
Configure event filtering and testing
-
Select and configure targets
-
Configure the rule settings
Choose the events
First, choose the events you want to send to the target.
To select an event
-
Open the Amazon EventBridge console at https://console.aws.amazon.com/events/
. -
In the navigation pane, choose Rules, and then choose Create Rule.
-
In the Events tab, find the events you want to send to the target:
-
Choose Amazon Service Events or Custom Events.
-
Use the Search box or browse the event list to find the events you want to send to the target.
-
Drag one or more events into the Build canvas and drop it on Triggering Events.
EventBridge displays the Triggering Events section. This section includes:
-
Events, which lists the event you chose.
-
Schema, which displays the schema of the selected event, if available.
Schema contains three tabs:
Tree: A tree view of the event schema.
Code: The event schema in Open API spec or JSON format.
Info: Overview information about the schema.
-
Sample event, which displays a sample of a selected event, if available.
-
Event pattern (filter), which contains an event pattern that selects all events you've chosen.
-
Filter events to send only what you want
You probably won't want to send all events of a specific type to a target. You can make your event pattern more specific so that it only selects events that contain the attributes and values you're interested in.
Edit the event pattern (optional)
In the Triggering events pane, you can build the event pattern two ways:
Visually, using the Schema tree view
By directly editing the JSON in the Event pattern pane
To edit the event pattern using the Schema tree view
-
Choose the Tree tab of the Schema pane.
-
Add and edit filters to build out the event pattern.
Choose the filter icon next to the attribute you want to add as a filter to the event pattern.
-
Choose a comparison operator from the drop-down list.
For more information on comparison operators, see Creating event patterns.
Enter the value you want to match.
Click the check mark to finish.
EventBridge adds the filter you've created to the JSON in the Event pattern pane.
-
Add additional filters until you've constructed an event pattern that matches on all the event attributes you want.
Test the event pattern
After you construct an event pattern that matches all the event attributes you want, test to ensure the event pattern performs as expected.
Test the event pattern (optional)
-
Choose a sample event for testing, or use your own.
-
Use sample events provided
Choose Use sample events provided.
-
Under Sample triggering event, select the event to use for testing from the drop-down list.
-
Use your own event
-
Choose Use your own event.
EventBridge displays a generic event with an empty
detailselement. -
Edit the event JSON to create the event against which you want to test your event pattern.
Tip
You can use the sample events provided as starting points for creating your own custom events to use in your testing:
-
Choose Use sample events provided, choose an event from the Sample triggering event, and then choose Copy.
-
Choose Use your own event.
-
Select the entire event in the window, and paste the sample event over it.
Edit the event as desired.
-
-
-
-
Choose Run Test.
EventBridge displays a message stating whether the test event matches the event pattern.
Select targets
Drag one (and up to five) targets into the Build canvas and drop it on Targets to receive events that match the specified event pattern. Targets can include:
Other EventBridge event buses, in the same or a different Amazon Web Services account
EventBridge API destinations, including SaaS partners such as Salesforce
A range of Amazon service resources, such as Amazon SQS queues or Amazon SNS topics
To select targets
-
Select the target type from the Targets pane, and drop it onto the Targets shape in the Build canvas.
EventBridge displays the Target section in the Build, with the applicable configuration options based on the type of target you selected.
Tip
If you have specified more than one target, selecting the target shape displays the configuration section for that target.
-
Configure the target based on your target type. For detailed configuration steps, see EventBridge Targets.
Customize the event data sent to the target
If you select a target other than an EventBridge event bus or EventBridge API destination, you have the option of customizing what data actually gets delivered to the target.
Transform or replace the event data sent (optional)
-
In the Build design canvas, choose the Input transformation icon in the Targets shape.
EventBridge displays the Input transformation section.
-
Under Input transformation configuration, choose Enable.
-
Select the Transformation method to choose how you want to customize the text sent to the target for matching events:
Part of the matched events – EventBridge only sends the specified portion of the original source event to the target.
Constant (JSON text) – EventBridge sends only the specified JSON text to the target. No part of the original source event is sent.
Input transformer – Configure an input transformer to customize the text you want EventBridge to send to the target. For more information, see Transforming target input.
Configure the rule
Finally, configure and create the rule.
To configure the rule (console)
-
Choose Configure.
-
Enter a Name and, optionally, a Description for the rule.
A rule can't have the same name as another rule in the same Amazon Web Services Region and on the same event bus.
-
For Event bus, choose the event bus to associate with this rule.
If you want this rule to match events that come from your account, select Amazon default event bus. When an Amazon Web Services service in your account sends an event, it always goes to your account's default event bus.
-
To enable the rule as soon as it is created, under Activation enable Active.
-
(Optional) Enter one or more tags for the rule. For more information, see Tagging resources in Amazon EventBridge.
Choose Create.
Next steps
After creating your rule, you can:
Additional resources
For more information about EventBridge rules, see: