

# Archiving and replaying events in Amazon EventBridge
<a name="eb-archive"></a>

In EventBridge, you can create an archive of events so that you can easily *replay*, or resend them to the event bus that originally received them, at a later time. For example, you might want to replay events to recover from errors, or to validate new functionality in your application.

## Archiving events
<a name="eb-archive-archive"></a>

When you create an archive, you can specify: 
+ Which events to send to the archive.

  You can specify an event pattern for EventBridge to use when filtering the events it sends to the archive.
+ How long to retain events in the archive.

  You can specify the number of days to retain events in the archive. By default, EventBridge stores events in an archive indefinitely.

Each archive receives events from a single *source* event bus. You cannot change the source event bus once an archive is created. You can create multiple archives for a given event bus.

![\[Events are filtered by an event pattern and sent to an archive, from which they can be replayed.\]](http://docs.aws.amazon.com/eventbridge/latest/userguide/images/archive_eventbridge_conceptual.svg)


EventBridge charges apply to archives. Please refer to [Amazon EventBridge Pricing](https://aws.amazon.com/eventbridge/pricing/) for details.

### Encrypting archive events
<a name="eb-archive-encryption"></a>

By default, EventBridge encrypts event data in an archive using 256-bit Advanced Encryption Standard (AES-256) under an [AWS owned CMK](https://docs.aws.amazon.com//kms/latest/developerguide/concepts.html#aws-owned-cmk), which helps secure your data from unauthorized access.

### Event delivery
<a name="eb-archive-timing"></a>

Keep in the following considerations in mind about how EventBridge delivers events to archives:
+ There may be a delay between an event being received on an event bus and the event arriving in the archive. We recommend you delay replaying archived events for 10 minutes to make sure all events are replayed.
+ The `EventCount` and `SizeBytes` values of the [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_DescribeArchive.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_DescribeArchive.html) operation have a reconciliation period of 24 hours. Therefore, any recently-expired or newly-archived events may not be immediately reflected in these values.

### Preventing replayed events from being delivered to an archive
<a name="eb-archive-managed-rule"></a>

When you create an archive, EventBridge generates a [managed rule](eb-rules.md#eb-rules-managed) on the source event bus that prevents replayed events from being sent to the archive. The managed rule adds the following event pattern, which filters events based on whether it contains a `replay-name` field. (EventBridge adds this field to events when it replays them.)

```
{
  "replay-name": [{
    "exists": false
  }]
}
```

## Replaying events from an archive
<a name="eb-archive-replay"></a>

After you create an archive, you can then replay events from the archive. For example, if you update an application with additional functionality, you can replay historical events to ensure that the events are reprocessed to keep the application consistent. You can also use an archive to replay events for new functionality.

When you replay events from an archive, you specify:
+ The time frame from which to select events to replay.
+ Optionally, specific rules on the event bus to which EventBridge should replay the selected events.

Archive events can only be replayed to the source event bus.

You can have a maximum of ten active concurrent replays per account per AWS Region.

Replaying events does not remove them from the archive. You can replay events in multiple replays. EventBridge only removes events when they exceed the archive retention period, or you delete the archive itself.

EventBridge deletes replays after 90 days.

You can cancel replays while their status is `Starting` or `Running`. For more information, see [Canceling event replays](eb-replay-cancel.md).

### Identifying events that have been replayed
<a name="eb-archive-replay-event-transform"></a>

When EventBridge sends an event from an archive to the source event bus during a replay, it adds a metadata field to the event, `replay-name`, which contains the name of the replay. You can use this field to identify replayed events when they are delivered to a target.

EventBridge also uses this field to make sure that replayed events aren't sent to archives.

### Considerations when replaying events from an archive
<a name="eb-archive-replay-considerations"></a>

Keep the following considerations in mind when replaying events from an archive:
+ There may be a delay between an event being received on an event bus and the event arriving in the archive. We recommend you delay replaying archived events for 10 minutes to make sure all events are replayed.
+ Events aren't necessarily replayed in the same order that they were added to the archive. A replay processes events to replay based on the time in the event, and replays them on one minute intervals. If you specify an event start time and an event end time that covers a 20 minute time range, the events are replayed from the first minute of that 20 minute range first. Then the events from the second minute are replayed.
+ You can use the `DescribeReplay` operation of the EventBridge API to determine the progress of a replay. `EventLastReplayedTime` returns the time stamp of the last event replayed.
+ Events are replayed based on, but separate from, the `PutEvents` transactions per second limit for the AWS account. You can request an increase to the limit for PutEvents. For more information, see [ Amazon EventBridge Quotas](https://docs.aws.amazon.com/eventbridge/latest/userguide/cloudwatch-limits-eventbridge.html).

 The following video demonstrates the use of archive and replay:




# Creating event archives in Amazon EventBridge
<a name="eb-archive-event"></a>

When you create an archive in EventBridge, you can determine which events are sent to the archive by specifying an [event pattern](eb-event-patterns.md). EventBridge sends events that match the event pattern to the archive. You also set the retention period to store events in the archive before they are discarded.

You can also create archives as part of [creating an event bus](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-event-bus.html). These archives have an indefinite retention policy and no event filter, although this can be [updated](https://docs.aws.amazon.com/eventbridge/latest/userguide/event-bus-update-archive.html) once the archive is created.

**Topics**
+ [Define the archive](#eb-create-archive-define)
+ [Build the event pattern (optional)](#eb-create-archive-event-pattern)

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

First, enter a name and description for archive, and specify the event bus from which it receives events. Optionally, you can also set how long to retain events in the archive.

**To define the archive**

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

1. Navigate to the source event bus, or create the archive directly:
   + In the navigation pane, choose **Event buses**.

     On the events bus details page, choose the **Archives** tab.
   + In the navigation pane, choose **Archives**.

1. Choose **Create archive**.

1. Under **Archive detail**, enter a name and optionally, a description for the archive. 

    The name must be unique to your account in the selected Region. You can't change the name after you create the archive.

1. For **Source**, select the event bus you want to send events to the archive

   If you navigated from an existing event bus details page, the name of that event bus appears by default.

   You cannot change the source event bus once you have created the archive.

1. For **Retention period**, specify how long to retain the events in the archive:
   + Choose **Indefinite** to retain the events in the archive and not ever delete them.
   + For a set retention period, enter the number of days after which EventBridge should delete the events from the archive.

1. For **Encryption**, choose the KMS key for EventBridge to use when encrypting the events stored in the archive.
**Important**  
If you have specify that EventBridge use a customer managed key for encrypting the source event bus, we strongly recommend you also specify a customer managed key for any archives for the event bus as well.
   + Choose **Use AWS owned key** for EventBridge to encrypt the data using an AWS owned key.

     This AWS owned key is a KMS key that EventBridge owns and manages for use in multiple AWS accounts. In general, unless you are required to audit or control the encryption key that protects your resources, an AWS owned key is a good choice. 

     This is the default.
   + Choose **Use customer managed key** for EventBridge to encrypt the data using the customer managed key that you specify or create.

     Customer managed key are KMS keys in your AWS account that you create, own, and manage. You have full control over these KMS keys.

     1. Specify an existing customer managed key, or choose **Create a new KMS key />**.

       EventBridge displays the key status and any key aliases that have been associated with the specified customer managed key.

1. Choose **Next**.

## Build the event pattern (optional)
<a name="eb-create-archive-event-pattern"></a>

Next, as an optional step, you can build an event pattern to filter which events EventBridge sends to the archive. 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.

For more information on event patterns, see [](eb-event-patterns.md).

**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 **Create archive**.

To confirm that events are successfully sent to the archive, you can use the [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_DescribeArchive.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_DescribeArchive.html) operation of the EventBridge API to see if the `EventCount` reflects the number of events in the archive. If it is 0, there are no events in the archive.

# Updating archives on Amazon EventBridge event buses
<a name="event-bus-update-archive"></a>

You can update the following: 
+ Archive description
+ The event pattern used to filter which events are sent to the archive.
+ The retention period for events.
+ The AWS KMS key used for event encryption.

  For more information, see [Encrypting archives](encryption-archives.md).

You cannot change the name or source event bus for an archive once it has been created.

**Note**  
Schema discovery is not supported for event buses encrypted using a customer managed key. To enable schema discovery on an event bus, choose to use an AWS owned key. For more information, see [KMS key options](eb-encryption-at-rest-key-options.md).

**To update an archive (console)**

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

1. Navigate to the archive directly, or from the source event bus:
   + In the navigation pane, choose **Event buses**.

     On the events bus details page, choose the **Archives** tab.
   + In the navigation pane, choose **Archives**.

1. Select the archive, and then select **Edit**.

1. Update the archive.

**To update an archive for an event bus (AWS CLI)**
+ Use [update-archive](https://docs.aws.amazon.com/cli/latest/reference/events/update-archive.html).

# Deleting event archives in Amazon EventBridge
<a name="eb-archive-delete"></a>

When you delete an archive, EventBridge deletes the following resources:
+ The archive and any events it contains.
+ The event pattern, if any, specified for the archive.
+ The managed rule EventBridge generated for the archive.

**To delete an archive from an event bus (console)**

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

1. Navigate to the archive directly, or from the source event bus:
   + In the navigation pane, choose **Event buses**.

     On the events bus details page, choose the **Archives** tab.
   + In the navigation pane, choose **Archives**.

1. Choose the event bus that contains the archive you want to delete.

1. On the event bus details page, select the **Archives** tab.

1. Select the archive, and then select **Delete**.

**To delete an archive (AWS CLI)**
+ Use [delete-archive](https://docs.aws.amazon.com/cli/latest/reference/events/delete-archive.html).

# Creating replays of archived events in Amazon EventBridge
<a name="eb-replay-archived-event"></a>

When you start a new replay, you specify a time period for the event you want EventBridge to resend to the source event bus. You can also specify for EventBridge to send the events to specific rules.

**To start an event replay (console)**

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

1. Navigate to the replays directly, or from the archive you want to replay:
   + In the navigation pane, choose **Archives**.

     On the **Archives** page, choose the archive and then choose**Replay**.
   + In the navigation pane, choose **Replays**.

     Choose **Start new replay**.

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

1. For **Source**, select the archive to replay events from.

1. For destination, you can replay events only to the same event bus that emitted the events.

1. For **Specify rules**, do one of the following:
   + Choose **All rules** to replay events to all rules.
   + Choose **Specify rules**, and then select the rule or rules to replay the events to.

1. Under **Replay time frame**, specify the **Date**, **Time**, and **Time zone** for the **Start time** and the **End time**. 

   Only events that occurred between the **Start time** and **End time** are replayed. 

1. Choose **Start replay**.

**To start a replay (AWS CLI)**
+ Use [start-replay](https://docs.aws.amazon.com/cli/latest/reference/events/start-replay.html).

# Canceling replays of archived events in Amazon EventBridge
<a name="eb-replay-cancel"></a>

If you start a replay and then want to stop it, you can cancel it while its status is `Starting` or `Running`.

**To cancel a replay (console)**

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

1. In the left navigation pane, choose **Replays**.

1. Choose the replay to cancel.

1. Choose **Cancel**.

**To cancel a replay (AWS CLI)**
+ Use [cancel-replay](https://docs.aws.amazon.com/cli/latest/reference/events/cancel-replay.html).