# EventBridge

> Put events on EventBridge buses and check the events your services put there.

Source: https://axx.nimbusxr.us/next/references/packs/aws-eventbridge/

Put events on EventBridge buses and check the events your services put there.

The steps use the scenario's AWS account (`the {word} aws account with the following properties:`, from aws-core). An event has a detail type, a source and a JSON detail, as in `When a "Damage Reported" event from carrier.kestrel is put on the carrier-events eventbridge bus:` with the detail as the doc string.

**Checking a bus** does not take events from anyone: for the buses a run checks, Axx adds a rule of its own (`axx-<run>-<bus>`, matching every event of the account) with a queue of its own as its target once the services are up, and removes both when the run ends. The conditions are paths into the event as EventBridge delivers it: `detail-type`, `source`, and `detail.<field>` for the detail. A check only looks at the events received since its scenario started.

Add it to a project with `axx pack add aws-eventbridge`; it builds on [`aws-core`](https://axx.nimbusxr.us/next/references/packs/aws-core/), which comes with it.

## Steps

### `aws-eventbridge.put`

```gherkin
When a(n) {string} event from {word} is put on the {word} eventbridge bus:
  """
  ...
  """
```

Put an event with that detail type and source on the bus; the doc string is its detail, in JSON.

| Parameter | Takes | For example |
|---|---|---|
| `{string}` | text in double or single quotes, which the step leaves out | `"Get a quote"`, `'Express'` |
| `{word}` | one word, with no spaces | `parcels`, `PX-4101` |

**Example:**

```gherkin
When a "Damage Reported" event from carrier.kestrel is put on the carrier-events eventbridge bus:
  """
  {"parcel": "PX-4105", "carrier": "KESTREL", "note": "Crushed at the depot"}
  """
```

_Since 0.1.0._

### `aws-eventbridge.received`

```gherkin
Then [[within {duration} ]]the {word} eventbridge bus has an event where:
  | path | value |
```

The table may start with the row naming its columns, as above, or go straight to its rows.

Check that the bus has an event with those values, put since the scenario started.

- The check waits for it: 10 seconds, or `within {duration}`.
- Axx adds a rule of its own to the bus for the run.

| Parameter | Takes | For example |
|---|---|---|
| `{duration}` | a duration in seconds (`s`) or minutes (`m`) | `5s`, `2m` |
| `{word}` | one word, with no spaces | `parcels`, `PX-4101` |

| Path | Takes |
|---|---|
| `detail-type` | the event's detail type, like `Claim Decided` |
| `source` | the event's source, like `parcels.claims` |
| `detail.<field>` | a field of the event's detail, or a dotted path into it, like `detail.claim` |

Values compare as text: `null` for null and `undefined` for absent. Other paths into the event, as EventBridge delivers it, work too, like `account` or `region`.

**Variants**, the parts in `[[...]]` said or left out:

- `the {word} eventbridge bus has an event where:`
- `within {duration} the {word} eventbridge bus has an event where:`

**Example:**

```gherkin
Then within 30s the parcels eventbridge bus has an event where:
  | detail-type     | Claim Decided  |
  | source          | parcels.claims |
  | detail.claim    | CLM-4101       |
  | detail.decision | APPROVED       |
```

_Since 0.1.0._
