# SNS

> Publish messages to SNS topics and check the messages your services publish.

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

Publish messages to SNS topics and check the messages your services publish.

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

**Checking a topic** does not take messages from anyone: for the topics a run checks, Axx subscribes a queue of its own (`axx-<run>-<topic>`, with raw message delivery) once the services are up, and removes the subscription and the queue when the run ends. A check only looks at the messages received since its scenario started; match on data unique to the scenario, since scenarios run in parallel.

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

## Steps

### `aws-sns.send`

```gherkin
When a message is published to the {word} sns topic:
  """
  ...
  """
```

Send a message to the sns topic; the doc string is its body.

| Parameter | Takes | For example |
|---|---|---|
| `{word}` | one word, with no spaces | `parcels`, `PX-4101` |

**Example:**

```gherkin
When a message is published to the parcel-events sns topic:
  """
  {"parcel": "PX-4104", "status": "DELIVERED", "deliveredAt": "2026-09-20T14:05:00Z"}
  """
```

_Since 0.1.0._

### `aws-sns.send.file`

```gherkin
When the {filepath} message is published to the {word} sns topic[[ with the following attributes:]]
```

Send a message whose body is the file to the sns topic, with the attributes of the table when the step has one.

| 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` |
| `{word}` | one word, with no spaces | `parcels`, `PX-4101` |

Each row is an attribute sent with the message, as text: its name and its value.

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

- `the {filepath} message is published to the {word} sns topic`
- `the {filepath} message is published to the {word} sns topic with the following attributes:`

**Example:**

```gherkin
When the messages/px-4104-delivered.json message is published to the parcel-events sns topic
When the messages/px-4104-delivered.json message is published to the parcel-events sns topic with the following attributes:
  | eventType | ParcelDelivered |
```

_Since 0.1.0._

### `aws-sns.received`

```gherkin
Then [[within {duration} ]]the {word} sns topic has a message where:
  | path | value |
```

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

Check that the sns topic has a message with those values, received since the scenario started.

- The check waits for it: 10 seconds, or `within {duration}`.
- Axx subscribes a queue of its own to the topic 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` |

Each row is a path into the message's JSON body (a field name, a dotted path or a JSONPath) and the value it has, compared as text: `null` for null and `undefined` for absent. A row `attribute <name>` is instead on the attribute of that name sent with the message: `undefined` when there is none.

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

- `the {word} sns topic has a message where:`
- `within {duration} the {word} sns topic has a message where:`

**Example:**

```gherkin
Then within 30s the claim-decisions sns topic has a message where:
  | claim               | CLM-4101     |
  | decision            | APPROVED     |
  | attribute eventType | ClaimDecided |
```

_Since 0.1.0._
