

# Rules in Amazon EventBridge
<a name="eb-rules"></a>

You specify what EventBridge does with the events delivered to each event bus. To do this, you create *rules*. A rule specifies which events to send to which [targets](eb-targets.md) for processing. A single rule can send an event to multiple targets, which then run in parallel.

You can create two types of rules: rules that match on event data as events are delivered, and rules that run on a defined schedule. In addition, certain AWS services may create and manage rules in your account as well.

## Rules that match on event data
<a name="eb-rules-match"></a>

You can create rules that match against incoming events based on event data criteria (called an *event pattern*). An event pattern defines the event structure and the fields that a rule matches. If an event matches the criteria defined in the event pattern, EventBridge sends it to the target(s) you specify.

For more information, see [Creating rules in Amazon EventBridge](eb-create-rule-visual.md).

## Rules that run on a schedule
<a name="eb-rules-scheduled"></a>

**Note**  
Scheduled rules are a legacy feature of EventBridge.  
EventBridge offers a more flexible and powerful way to create, run, and manage scheduled tasks centrally, at scale: EventBridge Scheduler. With EventBridge Scheduler, you can create schedules using cron and rate expressions for recurring patterns, or configure one-time invocations. You can set up flexible time windows for delivery, define retry limits, and set the maximum retention time for failed API invocations.   
Scheduler is highly customizable, and offers improved scalability over scheduled rules, with a wider set of target API operations and AWS services. We recommend that you use Scheduler to invoke targets on a schedule.  
For more information, see [Create a schedule](using-eventbridge-scheduler.md#using-eventbridge-scheduler-create) or the *[EventBridge Scheduler User Guide](https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html)*.

You can also create rules that sends events to the specified targets at specified intervals. For example, to periodically run an Lambda function, you can create a rule to run on a schedule.

For more information, see [Creating a scheduled rule (legacy) in Amazon EventBridge](eb-create-rule-schedule.md).

## Rules managed by AWS services
<a name="eb-rules-managed"></a>

In addition to the rules you create, AWS services can create and manage EventBridge rules in your AWS account that are needed for certain functions in those services. These are called *managed rules*. 

When a service creates a managed rule, it can also create an [IAM policy](eb-iam.md) that grants permission to that service to create the rule. IAM policies created this way are scoped narrowly with resource-level permissions to allow the creation of only the necessary rules.

You can delete managed rules by using the **Force delete** option, but you should only delete them if you're sure that the other service no longer needs the rule. Otherwise, deleting a managed rule causes the features that rely on it to stop working.

# Creating rules in Amazon EventBridge
<a name="eb-create-rule-visual"></a>

## Prerequisites
<a name="eb-create-rule-prerequisites"></a>

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
<a name="eb-create-rule-overview"></a>

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:

1. Choose the events you want to process

1. Configure event filtering and testing

1. Select and configure targets

1. Configure the rule settings

## Choose the events
<a name="eb-create-rule-source"></a>

First, choose the events you want to send to the target.

**To select an event**

1. Open the Amazon EventBridge console at [https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/).

1. In the navigation pane, choose **Rules**, and then choose **Create Rule**.

1. In the **Events** tab, find the events you want to send to the target:

   1. Choose **AWS Service Events** or **Custom Events**.

   1. Use the Search box or browse the event list to find the events you want to send to the target.

   1. 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
<a name="eb-create-rule-event-pattern-visual"></a>

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)
<a name="eb-create-rule-event-pattern-steps"></a>

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**

1. Choose the **Tree** tab of the **Schema** pane.

1. Add and edit filters to build out the event pattern.

   1. Choose the filter icon next to the attribute you want to add as a filter to the event pattern.

   1. Choose a comparison operator from the drop-down list.

      For more information on comparison operators, see [Creating event patterns](eb-create-pattern-operators.md).

   1. Enter the value you want to match.

   1. Click the check mark to finish.

   EventBridge adds the filter you've created to the JSON in the **Event pattern** pane.

1. Add additional filters until you've constructed an event pattern that matches on all the event attributes you want.

### Test the event pattern
<a name="eb-create-rule-event-pattern-test"></a>

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)
<a name="eb-create-rule-event-pattern-test-steps"></a>

1. Choose a sample event for testing, or use your own.
   + **Use sample events provided**

     1. Choose **Use sample events provided**.

     1. Under **Sample triggering event**, select the event to use for testing from the drop-down list.
   + **Use your own event**

     1. Choose **Use your own event**.

        EventBridge displays a generic event with an empty `details` element.

     1. 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.

1. Choose **Run Test**.

   EventBridge displays a message stating whether the test event matches the event pattern.

## Select targets
<a name="eb-create-rule-target-visual"></a>

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 AWS account
+ EventBridge API destinations, including SaaS partners such as Salesforce
+ A range of AWS service resources, such as Amazon SQS queues or Amazon SNS topics

**To select targets**

1. 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.

1. Configure the target based on your target type. For detailed configuration steps, see [EventBridge Targets](eb-targets.md).

### Customize the event data sent to the target
<a name="eb-create-rule-target-transform"></a>

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)
<a name="eb-create-rule-target-transform-steps"></a>

1. In the Build design canvas, choose the **Input transformation** icon in the **Targets** shape.

   EventBridge displays the **Input transformation** section.

1. Under **Input transformation configuration**, choose **Enable**.

1. 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](eb-transform-target-input.md).

## Configure the rule
<a name="eb-create-rule-configure"></a>

Finally, configure and create the rule.

**To configure the rule (console)**

1. Choose **Configure**.

1. Enter a **Name** and, optionally, a **Description** for the rule.

   A rule can't have the same name as another rule in the same AWS Region and on the same event bus.

1. 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 **AWS default event bus**. When an AWS service in your account sends an event, it always goes to your account's default event bus.

1. To enable the rule as soon as it is created, under **Activation** enable **Active**.

1. (Optional) Enter one or more tags for the rule. For more information, see [Tagging resources in Amazon EventBridge](eb-tagging.md).

1. Choose **Create**.

## Next steps
<a name="eb-create-rule-next-steps"></a>

After creating your rule, you can:
+ [Monitor rule performance using metrics](eb-monitoring.md)
+ [Test your rule with sample events](eb-event-pattern-sandbox.md)
+ [Modify event patterns as needed](eb-event-patterns.md)
+ [Add additional targets to existing rules](eb-targets.md)

## Additional resources
<a name="eb-create-rule-additional-resources"></a>

For more information about EventBridge rules, see:
+ [EventBridge rules overview](eb-rules.md)
+ [Creating event patterns](eb-event-patterns.md)
+ [EventBridge targets](eb-targets.md)
+ [Troubleshooting EventBridge rules](eb-troubleshooting.md)

# Creating rules that react to events in Amazon EventBridge
<a name="eb-create-rule-wizard"></a>

To take action on events received by Amazon EventBridge, you can create [rules](eb-rules.md). When an event matches the [event pattern](eb-event-patterns.md) defined in your rule, EventBridge sends the event to the specified [target](eb-targets.md) and triggers the action defined in the rule.

The following steps walk you through how to create a rule that EventBridge uses to match events as they are sent to the specified event bus.

**Topics**
+ [Define the rule](#eb-create-rule-define)
+ [Build the event pattern](#eb-create-rule-event-pattern)
+ [Select targets](#eb-create-rule-target)
+ [Configure tags and review rule](#eb-create-rule-review)

## Define the rule
<a name="eb-create-rule-define"></a>

First, enter a name and description for your rule to identify it. You must also define the event bus where your rule looks for events to match to an event pattern.

**To define the rule detail**

1. Open the Amazon EventBridge console at [https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/).

1. In the navigation pane, choose **Rules**.

1. Choose **Create rule**.

1. Enter a **Name** and, optionally, a **Description** for the rule.

   A rule can't have the same name as another rule in the same AWS Region and on the same event bus.

1. 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 **AWS default event bus**. When an AWS service in your account emits an event, it always goes to your account’s default event bus.

1. For **Rule type**, choose **Rule with an event pattern**.

1. Choose **Next**.

## Build the event pattern
<a name="eb-create-rule-event-pattern"></a>

Next, build the event pattern. To do this, specify the event source, choose the basis for the event pattern, and define the attributes and values to match on. You can also generate the event pattern in JSON and test it against a sample event.

**To build the event pattern**

1. For **Event source**, choose **AWS events or EventBridge partner events**.

1. (Optional) In the **Sample events** section, choose a **Sample event type** against which you want to test your event pattern. 

   The following sample event types are available:
   + **AWS events **– Select from events emitted from supported AWS services.
   + **EventBridge partner events** – Select from events emitted from third-party services that support EventBridge, such as Salesforce.
   + **Enter my own** – Enter your own event in JSON text.

     You can also use an AWS or partner event as the starting point for creating your own custom event.

     1. Select **AWS events** or **EventBridge partner events**.

     1. Use the **Sample events** dropdown to select the event you want to use as a starting point for your custom event.

        EventBridge displays the sample event.

     1. Select **Copy**.

     1. Select **Enter my own** for **Event type.**

     1. Delete the sample event structure in the JSON editing pane, and paste the AWS or partner event in its place.

     1. Edit the event JSON to create your own sample event.

1. Choose a **Creation method**. You can create an event pattern from an EventBridge schema or template, or you can create a custom event pattern.

------
#### [ Existing schema ]

   To use an existing EventBridge schema to create the event pattern, do the following:

   1. In the **Creation method** section, for **Method**, select **Use schema**.

   1. In the **Event pattern** section, for **Schema type**, select **Select schema from Schema registry**.

   1. For **Schema registry**, choose the dropdown box and enter the name of a schema registry, such as `aws.events`. You can also select an option from the dropdown list that appears.

   1. For **Schema**, choose the dropdown box and enter the name of the schema to use. For example, `aws.s3@ObjectDeleted`. You can also select an option from the dropdown list that appears.

   1. In the **Models** section, choose the **Edit** button next to any attribute to open its properties. Set the **Relationship** and **Value** fields as needed, then choose **Set** to save the attribute.
**Note**  
For information about an attribute's definition, choose the **Info** icon next to the attribute's name. For a reference on how to set attribute properties in your event, open the **Note** section of the attribute properties dialog box.  
To delete an attribute's properties, choose the **Edit** button for that attribute, then choose **Clear**.

   1. Choose **Generate event pattern in JSON** to generate and validate your event pattern as JSON text. 

   1. (Optional) To test the sample event against your test pattern, choose **Test pattern**. 

      EventBridge displays a message box stating whether your sample event matches the event pattern.

      You can also choose any of the following options:
      + **Copy** – Copy the event pattern to your device's clipboard.
      + **Prettify** – Makes the JSON text easier to read by adding line breaks, tabs, and spaces.

------
#### [ Custom schema ]

   To write a custom schema and convert it to an event pattern, do the following:

   1. In the **Creation method** section, for **Method**, choose **Use schema**.

   1. In the **Event pattern** section, for **Schema type**, choose **Enter schema**.

   1. Enter your schema into the text box. You must format the schema as valid JSON text.

   1. In the **Models** section, choose the **Edit** button next to any attribute to open its properties. Set the **Relationship** and **Value** fields as needed, then choose **Set** to save the attribute.
**Note**  
For information about an attribute's definition, choose the **Info** icon next to the attribute's name. For a reference on how to set attribute properties in your event, open the **Note** section of the attribute properties dialog box.  
To delete an attribute's properties, choose the **Edit** button for that attribute, then choose **Clear**.

   1. Choose **Generate event pattern in JSON** to generate and validate your event pattern as JSON text. 

   1. (Optional) To test the sample event against your test pattern, choose **Test pattern**. 

      EventBridge displays a message box stating whether your sample event matches the event pattern.

      You can also choose any of the following options:
      + **Copy** – Copy the event pattern to your device's clipboard.
      + **Prettify** – Makes the JSON text easier to read by adding line breaks, tabs, and spaces.

------
#### [ Event pattern ]

   To write a custom event pattern in JSON format, do the following:

   1. In the **Creation method** section, for **Method**, choose **Custom pattern (JSON editor)**.

   1. For **Event pattern**, enter your custom event pattern in JSON-formatted text. 

   1. (Optional) To test the sample event against your test pattern, choose **Test pattern**. 

      EventBridge displays a message box stating whether your sample event matches the event pattern.

      You can also choose any of the following options:
      + **Copy** – Copy the event pattern to your device's clipboard.
      + **Prettify** – Makes the JSON text easier to read by adding line breaks, tabs, and spaces.
      + **Event pattern form** – Opens the event pattern in Pattern Builder. If the pattern can't be rendered in Pattern Builder as-is, EventBridge warns you before it opens Pattern Builder.

------

1. Choose **Next**.

## Select targets
<a name="eb-create-rule-target"></a>

Choose one or more targets to receive events that match the specified pattern. Targets can include an EventBridge event bus, EventBridge API destinations, including SaaS partners such as Salesforce, or another AWS service.

**To select targets**

1. For **Target type**, choose one of the following target types:

------
#### [ Event bus ]

   1. Select **EventBridge event bus**.

   1. Choose the event bus to use as the target.
      + To use an event bus in the same AWS Region as this rule: 

        1. Select **Event bus in the same account and Region**.

        1. For **Event bus for target**, choose the dropdown box and enter the name of the event bus. You can also select the event bus from the dropdown list.

           For more information, see [Sending events between event buses in the same account and Region in Amazon EventBridge](eb-bus-to-bus.md).
      + To use an event bus in a different AWS Region or account as this rule:

        1. Select **Event bus in a different account or Region**.

        1. For **Event bus as target**, enter the ARN of the event bus you want to use.

           For more information, see: 
           + [Sending and receiving events between AWS accounts in Amazon EventBridge](eb-cross-account.md)
           + [Sending and receiving events between AWS Regions in Amazon EventBridge](eb-cross-region.md)

   1. For many target types, EventBridge needs permissions to send events to the target. In these cases, EventBridge can create the IAM role needed for your rule to run. 

      For **Execution role**, do one of the following:
      + To create a new execution role for this rule:

        1. Select **Create a new role for this specific resource**.

        1. Either enter a name for this execution role, or use the name generated by EventBridge.
      + To use an existing execution role for this rule:

        1. Select **Use existing role**.

        1. Enter or select the name of the execution role to use from the dropdown list.

   1. (Optional) For **Additional settings**, specify any of the optional settings available for your target type:

      (Optional) For **Dead-letter queue**, choose whether to use a standard Amazon SQS queue as a dead-letter queue. EventBridge sends events that match this rule to the dead-letter queue if they are not successfully delivered to the target. Do one of the following:
      + Choose **None** to not use a dead-letter queue.
      + Choose **Select an Amazon SQS queue in the current AWS account to use as the dead-letter queue** and then select the queue to use from the drop-down list.
      + Choose **Select an Amazon SQS queue in an other AWS account as a dead-letter queue** and then enter the ARN of the queue to use. You must attach a resource-based policy to the queue that grants EventBridge permission to send messages to it. 

        For more information, see [Granting permissions to the dead-letter queue](eb-rule-dlq.md#eb-dlq-perms).

------
#### [ API destination ]

   1. Select **EventBridge API destination**.

   1. Choose a new or existing API destination:
      + To use an existing API destination, select **Use an existing API destination**. Then select an API destination from the dropdown list.
      + To create a new API destination, select **Create a new API destination**. Then, provide the following details for the destination:
        + **Name** – Enter a name for the destination. 

          Names must be unique within your AWS account. Names can have up to 64 characters. Valid characters are **A-Z**, **a-z**, **0-9**, and **.** **\$1** **-** (hyphen).
        + (Optional) **Description** – Enter a description for the destination. 

          Descriptions can have up to 512 characters.
        + **API destination endpoint** – The URL endpoint for the target. 

          The endpoint URL must start with **https**. You can include the **\$1** as a path parameter wildcard. You can set path parameters from the target's `HttpParameters` attribute.
        + **HTTP method** – Select the HTTP method used when you invoke the endpoint.
        + (Optional) **Invocation rate limit per second** – Enter the maximum number of invocations accepted for each second for this destination. 

          This value must be greater than zero. By default, this value is set to 300.
        + **Connection** – Choose to use a new or existing connection: 
          + To use an existing connection, select **Use an existing connection** and select the connection from the dropdown list. 
          + To create a new connection for this destination select **Create a new connection**, then define the connection's **Name**, **Destination type**, and **Authorization type**. You can also add an optional **Description** for this connection.

   1. For many target types, EventBridge needs permissions to send events to the target. In these cases, EventBridge can create the IAM role needed for your rule to run. 

      For **Execution role**, do one of the following:
      + To create a new execution role for this rule:

        1. Select **Create a new role for this specific resource**.

        1. Either enter a name for this execution role, or use the name generated by EventBridge.
      + To use an existing execution role for this rule:

        1. Select **Use existing role**.

        1. Enter or select the name of the execution role to use from the dropdown list.

   1. (Optional) For **Additional settings**, specify any of the optional settings available for your target type:

      Note that EventBridge may not display all of the following fields for a given AWS service.

      1. (Optional) For Configure target input, choose how you want to customize the text sent to the target for matching events. Choose one of the following:
         + **Matched events** – EventBridge sends the entire original source event to the target. This is the default.
         + **Part of the matched events** – EventBridge only sends the specified portion of the original source event to the target.

           Under **Specify the part of the matched event**, specify a JSON path that defines the part of the event you want EventBridge to send 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.

           Under **Specify the constant in JSON**, specify the JSON text that you want EventBridge to send to the target instead of the event.
         + **Input transformer** – Configure an input transformer to customize the text you want EventBridge send to the target. For more information, see [Amazon EventBridge input transformation](eb-transform-target-input.md).

           1. Select **Configure input transformer**.

           1. Configure the input transformer following the steps in [Configuring an input transformer when creating a rule in EventBridge](eb-transform-input-rule.md).

      1. (Optional) Under **Retry policy**, specify how EventBridge should retry sending an event to a target after an error occurs.
         + **Maximum age of event** – Enter the maximum amount of time (in hours, minutes, and seconds) for EventBridge to retain unprocessed events. The default is 24 hours.
         + **Retry attempts** – Enter the maximum number of times EventBridge should retry sending an event to the target after an error occurs. The default is 185 times.

      1. (Optional) For **Dead-letter queue**, choose whether to use a standard Amazon SQS queue as a dead-letter queue. EventBridge sends events that match this rule to the dead-letter queue if they are not successfully delivered to the target. Do one of the following:
         + Choose **None** to not use a dead-letter queue.
         + Choose **Select an Amazon SQS queue in the current AWS account to use as the dead-letter queue** and then select the queue to use from the drop-down list.
         + Choose **Select an Amazon SQS queue in an other AWS account as a dead-letter queue** and then enter the ARN of the queue to use. You must attach a resource-based policy to the queue that grants EventBridge permission to send messages to it. 

           For more information, see [Granting permissions to the dead-letter queue](eb-rule-dlq.md#eb-dlq-perms).

   For more information, see [API destinations as targets in Amazon EventBridge](eb-api-destinations.md).

------
#### [ AWS service ]

   1. Select **AWS service**.

   1. For **Select a target**, select an AWS service to use as the target. 

   1. If you choose an AWS service that supports cross-account targets, you can select a target in the same account as the event bus, or a different account.
      + For a target in the same account, for **Target type** select **Target in this account**.

        1. Provide the information requested for the service you select.
**Note**  
The fields displayed vary depending on the service selected. For more information about available targets, see [Event bus targets available in the EventBridge console](eb-targets.md#eb-console-targets).

        1. For many target types, EventBridge needs permissions to send events to the target. In these cases, EventBridge can create the IAM role needed for your rule to run. 

           For **Execution role**, do one of the following:
           + To create a new execution role for this rule:

             1. Select **Create a new role for this specific resource**.

             1. Either enter a name for this execution role, or use the name generated by EventBridge.
           + To use an existing execution role for this rule:

             1. Select **Use existing role**.

             1. Enter or select the name of the execution role to use from the dropdown list.
      + For a target in a different account, for **Target type** select **Target in another AWS account**.

        1. Enter the ARN of the target resource to which you want to send events.

        1. Provide any additional information requested for the service you select.

        1. Select the name of the execution role to use from the dropdown list.

   1. (Optional) For **Additional settings**, specify any of the optional settings available for your target type:

      1. (Optional) For Configure target input, choose how you want to customize the text sent to the target for matching events. Choose one of the following:
         + **Matched events** – EventBridge sends the entire original source event to the target. This is the default.
         + **Part of the matched events** – EventBridge only sends the specified portion of the original source event to the target.

           Under **Specify the part of the matched event**, specify a JSON path that defines the part of the event you want EventBridge to send 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.

           Under **Specify the constant in JSON**, specify the JSON text that you want EventBridge to send to the target instead of the event.
         + **Input transformer** – Configure an input transformer to customize the text you want EventBridge send to the target. For more information, see [Amazon EventBridge input transformation](eb-transform-target-input.md).

           1. Select **Configure input transformer**.

           1. Configure the input transformer following the steps in [Configuring an input transformer when creating a rule in EventBridge](eb-transform-input-rule.md).

      1. (Optional) Under **Retry policy**, specify how EventBridge should retry sending an event to a target after an error occurs.
         + **Maximum age of event** – Enter the maximum amount of time (in hours, minutes, and seconds) for EventBridge to retain unprocessed events. The default is 24 hours.
         + **Retry attempts** – Enter the maximum number of times EventBridge should retry sending an event to the target after an error occurs. The default is 185 times.

      1. (Optional) For **Dead-letter queue**, choose whether to use a standard Amazon SQS queue as a dead-letter queue. EventBridge sends events that match this rule to the dead-letter queue if they are not successfully delivered to the target. Do one of the following:
         + Choose **None** to not use a dead-letter queue.
         + Choose **Select an Amazon SQS queue in the current AWS account to use as the dead-letter queue** and then select the queue to use from the drop-down list.
         + Choose **Select an Amazon SQS queue in an other AWS account as a dead-letter queue** and then enter the ARN of the queue to use. You must attach a resource-based policy to the queue that grants EventBridge permission to send messages to it. 

           For more information, see [Granting permissions to the dead-letter queue](eb-rule-dlq.md#eb-dlq-perms).

------

1. (Optional) Choose **Add another target** to add another target for this rule.

1. Choose **Next**.

## Configure tags and review rule
<a name="eb-create-rule-review"></a>

Finally, enter any desired tags for the rule, then review and create the rule.

**To configure tags, and review and create the rule**

1. (Optional) Enter one or more tags for the rule. For more information, see [Tagging resources in Amazon EventBridge](eb-tagging.md).

1. Choose **Next**.

1. Review the details for the new rule. To make changes to any section, choose the **Edit** button next to that section.

   When satisfied with the rule details, choose **Create rule**.

# Disabling or deleting a rule in Amazon EventBridge
<a name="eb-delete-rule"></a>

To stop a [rule](eb-rules.md) from processing [events](eb-events.md) or running on a schedule, you can delete or disable the rule. The following steps walk you through how to delete or disable an EventBridge rule.

**To delete or disable a rule**

1. Open the Amazon EventBridge console at [https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/).

1. In the navigation pane, choose **Rules**.

   Under **Event bus**, select the event bus that is associated with the rule.

1. Do one of the following:

   1. To delete a rule, select the button next to the rule and choose **Actions**, **Delete**, **Delete**.

      If the rule is a managed rule, enter the name of the rule to acknowledge that it is a managed rule and that deleting it may stop functionality in the service that created the rule. To continue, enter the rule name and choose **Force delete**.

   1. To temporarily disable a rule, select the button next to the rule and choose **Disable**, **Disable**.

      You can't disable a managed rule.

# Best practices when defining rules in Amazon EventBridge
<a name="eb-rules-best-practices"></a>

Below are some best practices to consider when you create rules for your event buses.

## Set a single target for each rule
<a name="eb-rules-best-practices-single-target"></a>

While you can specify up to five targets for a given rule, managing rules is easier when you specify a single target for each rule. If more than one target needs to receive the same set of events, we recommend duplicating the rule to deliver the same events to different targets. This encapsulation simplifies maintaining rules: if the needs of the event targets diverge over time, you can update each rule and its event pattern independently of the others.

## Set rule permissions
<a name="eb-rules-best-practices-permissions"></a>

You can enable event-consuming application components or services to be in control of managing their own rules. A common architectural approach adopted by customers is to isolate these application components or services by using separate AWS accounts. To enable the flow of events from one account to another, you must create a rule on one event bus that routes events to an event bus in another account. You can enable event-consuming teams or services to be in control of managing their own rules. You do this by specifying the appropriate permissions to their accounts through resource policies. This works across accounts and Regions. 

For more information, see [Permissions for event buses in Amazon EventBridge](eb-event-bus-perms.md).

For example of resource policies, see [Multi-account design patterns with Amazon EventBridge](https://github.com/aws-samples/amazon-eventbridge-resource-policy-samples/tree/main/patterns) on GitHub.

## Monitor rule performance
<a name="eb-rules-best-practices-monitor"></a>

Monitor your rules to make sure they are performing as you expect:
+ Monitor the `TriggeredRules` metric for missing data-points or anomalies can assist you in detecting discrepancies for a publisher that made a breaking change. For more information, see [Monitoring Amazon EventBridge](eb-monitoring.md). 
+ Alarm on anomalies or maximum expected count can also help detecting when a rule is matching against new events. This can happen when event publishers, including AWS services and SaaS partners, introduce new events when enabling new use-cases and features. When these new events are unexpected and lead to a higher volume than the processing rate of the downstream target, they can lead to an event backlog. 

  Such processing of unexpected events can also lead to unwanted billing charges.

  It can also trigger throttling of rules when the account goes over its aggregate target invocations per second service quota. EventBridge will still attempt to deliver events matched by throttled rules and retry up to 24 hours or as described within the target’s custom retry policy. You can detect and alarm throttled rules using the `ThrottledRules` metric
+ For low-latency use cases, you can also monitor latency using `IngestionToInvocationStartLatency`, which provides an indication of health of your event bus. Any extended periods of high latency over 30 seconds may indicate a service disruption or rule throttling.

# Using AWS Serverless Application Model templates to deploy Amazon EventBridge resources
<a name="eb-use-sam"></a>

You can build and test [rules](eb-rules.md) manually in the EventBridge console, which can help in the development process as you refine [event patterns](eb-event-patterns.md). However, once you are ready to deploy your application, it’s easier to use a framework like [AWS SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) to launch all your serverless resources consistently.

We'll use this [ example application](https://github.com/aws-samples/amazon-eventbridge-producer-consumer-example) to look into the ways you can use AWS SAM templates to build EventBridge resources. The template.yaml file in this example is a AWS SAM template that defines four [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) functions and shows two different ways to integrate the Lambda functions with EventBridge.

For a walkthrough of this example application, see [Tutorial: Create a sample Amazon EventBridge application](eb-tutorial-get-started.md).

 There are two approaches to using EventBridge and AWS SAM templates. For simple integrations where one Lambda function is invoked by one rule, the the **Combined template** approach is recommended. If you have complex routing logic, or you are connecting to resources outside of your AWS SAM template, the **Separated template** approach is the better choice.

**Topics**
+ [Combined template](#eb-combined-template)
+ [Separated template](#eb-separated-template)

## Combined template
<a name="eb-combined-template"></a>

The first approach uses the `Events` property to configure the EventBridge rule. The following example code defines an [event](eb-events.md) that invokes your Lambda function.

**Note**  
This example automatically creates the rule on the default [event bus](eb-event-bus.md), which exists in every AWS account. To associate the rule with a custom event bus, you can add the `EventBusName` to the template.

```
atmConsumerCase3Fn:
  Type: AWS::Serverless::Function
  Properties:
    CodeUri: atmConsumer/
    Handler: handler.case3Handler
    Runtime: nodejs12.x
    Events:
      Trigger:
        Type: CloudWatchEvent 
        Properties:
          Pattern:
            source:
              - custom.myATMapp
            detail-type:
              - transaction                
            detail:
              result:
                - "anything-but": "approved"
```

 This YAML code is equivalent to an event pattern in the EventBridge console. In YAML, you only need to define the event pattern, and AWS SAM automatically creates an IAM role with the required permissions. 

## Separated template
<a name="eb-separated-template"></a>

In the second approach to defining an EventBridge configuration in AWS SAM, the resources are separated more clearly in the template. 

1. First, you define the Lambda function:

   ```
   atmConsumerCase1Fn:
     Type: AWS::Serverless::Function
     Properties:
       CodeUri: atmConsumer/
       Handler: handler.case1Handler
       Runtime: nodejs12.x
   ```

1. Next, define the rule using an `AWS::Events::Rule` resource. The properties define the event pattern and can also specify [targets](eb-targets.md). You can explicitly define multiple targets.

   ```
   EventRuleCase1: 
     Type: AWS::Events::Rule
     Properties: 
       Description: "Approved transactions"
       EventPattern: 
         source: 
           - "custom.myATMapp"
         detail-type:
           - transaction   
         detail: 
           result: 
             - "approved"
       State: "ENABLED"
       Targets: 
         - 
           Arn: 
             Fn::GetAtt: 
               - "atmConsumerCase1Fn"
               - "Arn"
           Id: "atmConsumerTarget1"
   ```

1. Finally, define an `AWS::Lambda::Permission` resource that grants permission to EventBridge to invoke the target.

   ```
   PermissionForEventsToInvokeLambda: 
     Type: AWS::Lambda::Permission
     Properties: 
       FunctionName: 
         Ref: "atmConsumerCase1Fn"
       Action: "lambda:InvokeFunction"
       Principal: "events.amazonaws.com"
       SourceArn: 
         Fn::GetAtt: 
           - "EventRuleCase1"
           - "Arn"
   ```

# Generating an AWS CloudFormation template from an existing EventBridge rule
<a name="rule-generate-template"></a>

AWS CloudFormation enables you to configure and manage your AWS resources across accounts and regions in a centralized and repeatable manner by treating infrastructure as code. CloudFormation does this by letting you create *templates*, which define the resources you want to provision and manage.

EventBridge enables you to generate templates from the existing rules in your account, as an aid to help you jumpstart developing CloudFormation templates. You can select a single rule, or multiple rules to include in the template. You can then use these templates as the basis for [creating stacks](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html) of resources under CloudFormation management.

For more information on CloudFormation see [*The CloudFormation User Guide*.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)

**Note**  
EventBridge does not include [managed rules](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-rules.html) in the generated template.

You can also [generate a template from an existing event bus](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-generate-event-bus-template.html), including the rules that event bus contains.

**To generate an CloudFormation template from one or more rules**

1. Open the Amazon EventBridge console at [https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/).

1. In the navigation pane, choose **Rules**.

1. Under **Select event bus**, choose the event bus that contains the rules you want to include in the template.

1. Under **Rules**, choose the rules you want to include in the generated CloudFormation template.

   For a single rule, you can also choose the rule name to display the rule's details page.

1. Choose **CloudFormation Template**, and then choose which format you want EventBridge to generate the template in: **JSON** or **YAML**.

   EventBridge displays the template, generated in the selected format.

1. EventBridge gives you the option of downloading the template file, or copying the template to the clipboard.
   + To download the template file, choose **Download**.
   + To copy the template to the clipboard, choose **Copy**.

1. To exit the template, choose **Cancel**. 

Once you've customized your CloudFormation template as necessary for your use case, you can use it to [create stacks](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html) in CloudFormation.

## Considerations when using CloudFormation templates generated from Amazon EventBridge
<a name="eb-generate-rule-template-considerations"></a>

Consider the following factors when using a CloudFormation template you generated from EventBridge:
+ EventBridge does not include any passwords in the generate template.

  You can edit the template to include [template parameters](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html) that enable users to specify passwords or other sensitive information when using the template to create or update a CloudFormation stack.

  In addition, users can use Secrets Manager to create a secret in the desired region and then edit the generated template to employ [dynamic parameters](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html#dynamic-references-secretsmanager).
+ Targets in the generated template remain exactly as they were specified in the original event bus. This can lead to cross-region issues if you do not appropriately edit the template before using it to create stacks in other regions.

  Additionally, the generated template does not create the downstream targets automatically.