# DynamoDB

> Seed DynamoDB tables and check the items your services write.

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

Seed DynamoDB tables and check the items your services write.

The steps use the scenario's AWS account (`the {word} aws account with the following properties:`, from aws-core).

A **seed** is a YAML or JSON file that maps table names to the items to put, written as plain JSON (numbers become `N`, objects `M`, arrays `L`):

```yaml
insured-parcels:
  - reference: PX-CLM-1001
    declaredValue: 120
    carrier: KESTREL
```

**Checks** wait (10 seconds unless `within {duration}` says otherwise) until the table has an item, or a number of items, meeting every condition: `attribute | value` rows with a dotted path into maps (`address.city`), compared as text, `null` for null and `undefined` for absent. Items are read with a scan, which suits the small tables of a test environment.

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

## Steps

### `aws-dynamodb.seed`

```gherkin
Given a {filepath} dynamodb seed
```

Put the items of a seed file into their tables: YAML or JSON that maps table names to lists of items. Items are plain JSON: numbers become `N`, objects `M` and arrays `L`.

| Parameter | Takes | For example |
|---|---|---|
| `{filepath}` | a file of the project: a path relative to the feature file's directory, the `resources` directories or axx.yaml's directory (looked for in that order), or an absolute path, quoted when it has a space | `seeds/parcels.yaml`, `kafka/scan-delivered.json` |

**Example:**

```gherkin
Given a seeds/insured-parcels.yaml dynamodb seed
```

_Since 0.1.0._

### `aws-dynamodb.item`

```gherkin
Then [[within {duration} ]]the {word} dynamodb table has an item where:
  | attribute | value |
```

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

Check that the table has an item with those values in those attributes. The check waits for it: 10 seconds, or `within {duration}`.

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

Each row names an attribute of the item, or a dotted path into a map (`address.city`), and the value it has, compared as text: `null` for null and `undefined` for absent. Sets read as lists, and binary as base64.

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

- `the {word} dynamodb table has an item where:`
- `within {duration} the {word} dynamodb table has an item where:`

**Example:**

```gherkin
Then within 30s the claims dynamodb table has an item where:
  | id     | CLM-4101 |
  | status | APPROVED |
  | amount | 89.5     |
```

_Since 0.1.0._

### `aws-dynamodb.items`

```gherkin
Then [[within {duration} ]]the {word} dynamodb table has {int} item(s) where:
  | attribute | value |
```

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

Check that exactly that many items of the table have those values in those attributes. The check waits for it: 10 seconds, or `within {duration}`.

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

Each row names an attribute of the item, or a dotted path into a map (`address.city`), and the value it has, compared as text: `null` for null and `undefined` for absent. Sets read as lists, and binary as base64.

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

- `the {word} dynamodb table has {int} item(s) where:`
- `within {duration} the {word} dynamodb table has {int} item(s) where:`

**Example:**

```gherkin
Then the claims dynamodb table has 1 item where:
  | parcel | PX-4107 |
```

_Since 0.1.0._
