# Azion CLI data-stream

The Azion CLI `data-stream` commands create, list, describe, update, and delete the streams and templates of [Data Stream](/en/documentation/platform/data-stream/). Every verb takes a subcommand: `streams` acts on a stream, named with `--stream-id`, and `templates` acts on a template, named with `--template-id`. `azion list data-stream` also takes `data-sources`. The commands exist only on accounts that use [API v4](/en/documentation/devtools/cli/how-it-works/#accounts-profiles-and-tokens). The options every command accepts, such as `--format`, `--out`, and `-y`, are on [Global options](/en/documentation/devtools/cli/globals/).

---

## Create

`azion create data-stream` takes the `streams` or the `templates` subcommand.

### Streams

`azion create data-stream streams` creates a stream from a JSON file that holds the stream object:

```bash
azion create data-stream streams [flags]
```

| Flag     | Short | Type   | Default | Description                                                                                                                          |
| -------- | ----- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `--file` | —     | string | —       | Path to a JSON file with the stream object. Use `-` to read the JSON from standard input. Without it, the command asks for the path. |

The command has no flag for the template. The template ID goes in the `render_template` item of `transform`, and a file without that item fails with this error:

```text
Error: Failed to create stream: ["Template must be provided."]. Check your settings and try again. If the error persists, contact Azion support
```

This file, `stream.json`, creates a stopped stream named `my-stream`. It sends every Activity History event, rendered by the *Activity History Collector* preset template, to an HTTP endpoint:

```json
{
  "name": "my-stream",
  "active": false,
  "inputs": [{ "type": "raw_logs", "attributes": { "data_source": "activity_history" } }],
  "transform": [
    { "type": "sampling", "attributes": { "rate": 100 } },
    { "type": "render_template", "attributes": { "template": 251 } }
  ],
  "outputs": [{ "type": "standard", "attributes": { "url": "https://example.com/logs", "payload_format": "$dataset", "log_line_separator": "\n", "headers": {} } }]
}
```

`inputs` names the data source by its slug, `transform` holds the sampling rate and the template ID, and `outputs` holds the one endpoint. For each field and the values it takes, refer to [Stream settings](/en/documentation/platform/data-stream/stream-settings/#stream-object).

Saving an active stream that has a `sampling` item deactivates every other stream on the account, and the API returns no error. To run several streams at once, give each one a `filter_workloads` item instead, as described in [Stream settings](/en/documentation/platform/data-stream/stream-settings/#transform).

Pass the file to the create command:

```bash
azion create data-stream streams --file stream.json
```

The command prints the ID of the stream:

```text
Created stream with ID 19609
```

### Templates

`azion create data-stream templates` creates a custom template with the name and the data set you pass:

```bash
azion create data-stream templates [flags]
```

| Flag         | Short | Type   | Default  | Description                                                                                          |
| ------------ | ----- | ------ | -------- | ---------------------------------------------------------------------------------------------------- |
| `--active`   | —     | string | `"true"` | Whether the template is active: `true` or `false`.                                                   |
| `--data-set` | —     | string | —        | Path to a JSON file with the data set of the template. Use `-` to read the JSON from standard input. |
| `--file`     | —     | string | —        | Path to a JSON file with the attributes of the template.                                             |
| `--name`     | —     | string | —        | Name of the template.                                                                                |

`--data-set` takes a file path, not the JSON itself. An inline JSON string fails with this error:

```text
Error: Failed to read the data set file. Verify if the file name and its path are correct and the file's content has a valid JSON format
```

The data set is a JSON object whose entries are `"<key>": "$<variable>"`. This file, `data-set.json`, sends four *Activity History* variables:

```json
{
  "time": "$time",
  "title": "$title",
  "author_email": "$author_email",
  "resource_type": "$resource_type"
}
```

For the variables of each data source, refer to [Data sources and variables](/en/documentation/platform/data-stream/data-sources-and-variables/). For the data set format, refer to [Templates and payload](/en/documentation/platform/data-stream/templates-and-payload/#custom-templates).

This command creates a template named `my-template` from that file:

```bash
azion create data-stream templates --name my-template --data-set data-set.json
```

The command prints the ID of the template:

```text
Created template with ID 2996
```

A stream uses the template when its `render_template` item carries that ID, as in `"template": 2996`.

---

## List

`azion list data-stream` takes the `streams`, the `templates`, or the `data-sources` subcommand. The three commands take the same flags:

| Flag          | Short | Type   | Default | Description                                                                          |
| ------------- | ----- | ------ | ------- | ------------------------------------------------------------------------------------ |
| `--details`   | —     | —      | —       | Adds columns to the `streams` list. On `templates` and `data-sources`, it adds none. |
| `--filter`    | —     | string | —       | Text to filter the list by. It does not narrow the `templates` list.                 |
| `--order-by`  | —     | string | —       | Field to sort the list by.                                                           |
| `--page`      | —     | int    | `1`     | Number of the page to return.                                                        |
| `--page-size` | —     | int    | `50`    | Number of items on each page.                                                        |

### Streams

`azion list data-stream streams` lists the streams of your account with the `ID`, `NAME`, and `ACTIVE` columns. `--details` adds the `LAST EDITOR` and `LAST MODIFIED` columns.

```bash
azion list data-stream streams
```

The command prints one row per stream:

```text
ID     NAME       ACTIVE
19609  my-stream  false
```

### Templates

`azion list data-stream templates` lists the templates of your account with the `ID`, `NAME`, and `ACTIVE` columns:

```bash
azion list data-stream templates
```

The command prints one row per template. The list holds the five preset templates and the custom templates of the account, such as `my-template` with ID `2996`. The presets are *Applications Event Collector* (`2`), *WAF Event Collector* (`4`), *Functions Event Collector* (`86`), *Applications + WAF Event Collector* (`184`), and *Activity History Collector* (`251`).

`--filter` does not narrow this list. The command prints every template whatever the value of `--filter`.

### Data sources

`azion list data-stream data-sources` lists the data sources a stream can collect from, with the `SLUG`, `NAME`, and `ACTIVE` columns:

```bash
azion list data-stream data-sources
```

The command prints one row per data source. The four data sources, by slug and name, are:

| Slug                | Name              |
| ------------------- | ----------------- |
| `activity_history`  | Activity History  |
| `workloads`         | Workloads         |
| `functions_console` | Functions Console |
| `waf`               | WAF Events        |

The slug is the value of `data_source` in a stream file. Azion Console labels `workloads` *Applications* and `functions_console` *Functions*.

---

## Describe

`azion describe data-stream` takes the `streams` or the `templates` subcommand.

### Streams

`azion describe data-stream streams` prints the values of one stream:

```bash
azion describe data-stream streams [flags]
```

| Flag          | Short | Type | Default | Description                   |
| ------------- | ----- | ---- | ------- | ----------------------------- |
| `--stream-id` | —     | int  | —       | ID of the stream to describe. |

This command describes the stream with ID `19609`:

```bash
azion describe data-stream streams --stream-id 19609
```

The command prints the `ID`, `Name`, `Last Editor`, `Modified at`, `Product Version`, and `Active` fields of the stream. With `--format json`, it prints the full stream object, in the shape of the [stream file](#streams).

### Templates

`azion describe data-stream templates` prints the values of one template:

```bash
azion describe data-stream templates [flags]
```

| Flag            | Short | Type | Default | Description                     |
| --------------- | ----- | ---- | ------- | ------------------------------- |
| `--template-id` | —     | int  | —       | ID of the template to describe. |

This command describes the template with ID `2996`:

```bash
azion describe data-stream templates --template-id 2996
```

The command prints the `ID`, `Name`, `Last Editor`, `Modified at`, `Custom`, `Active`, and `Data Set` fields of the template. With `--format json`, it prints the full object: `active`, `created_at`, `custom`, `data_set`, `id`, `last_editor`, `last_modified`, and `name`. `data_set` is a JSON string.

---

## Update

`azion update data-stream` takes the `streams` or the `templates` subcommand.

### Streams

`azion update data-stream streams` changes the fields of a stream from a JSON file:

```bash
azion update data-stream streams [flags]
```

| Flag          | Short | Type   | Default | Description                                                                                  |
| ------------- | ----- | ------ | ------- | -------------------------------------------------------------------------------------------- |
| `--file`      | —     | string | —       | Path to a JSON file with the fields to change. Use `-` to read the JSON from standard input. |
| `--stream-id` | —     | int    | —       | ID of the stream to update.                                                                  |

The file carries only the fields to change, and the fields it leaves out keep their values. This file, `stream-update.json`, renames the stream:

```json
{
  "name": "my-stream-renamed"
}
```

Pass the file and the stream ID to the update command:

```bash
azion update data-stream streams --stream-id 19609 --file stream-update.json
```

The command prints the ID of the updated stream:

```text
Updated stream with ID 19609
```

A file that sets `"active": true` on a stream with a `sampling` item deactivates every other stream on the account.

### Templates

`azion update data-stream templates` changes the name, the data set, or the state of a template:

```bash
azion update data-stream templates [flags]
```

| Flag            | Short | Type   | Default | Description                                                                              |
| --------------- | ----- | ------ | ------- | ---------------------------------------------------------------------------------------- |
| `--active`      | —     | string | —       | Whether the template is active: `true` or `false`.                                       |
| `--data-set`    | —     | string | —       | Path to a JSON file with the new data set. Use `-` to read the JSON from standard input. |
| `--file`        | —     | string | —       | Path to a JSON file with the attributes to change.                                       |
| `--name`        | —     | string | —       | New name of the template.                                                                |
| `--template-id` | —     | int    | —       | ID of the template to update.                                                            |

This command renames the template with ID `2996` to `my-template-renamed`:

```bash
azion update data-stream templates --template-id 2996 --name my-template-renamed
```

The command prints the ID of the updated template:

```text
Updated template with ID 2996
```

---

## Delete

`azion delete data-stream` takes the `streams` or the `templates` subcommand.

### Streams

`azion delete data-stream streams` deletes a stream:

```bash
azion delete data-stream streams [flags]
```

| Flag          | Short | Type | Default | Description                 |
| ------------- | ----- | ---- | ------- | --------------------------- |
| `--stream-id` | —     | int  | —       | ID of the stream to delete. |

This command deletes the stream with ID `19609`:

```bash
azion delete data-stream streams --stream-id 19609 -y
```

The command confirms the deletion:

```text
Stream 19609 was successfully deleted
```

### Templates

`azion delete data-stream templates` deletes a custom template:

```bash
azion delete data-stream templates [flags]
```

| Flag            | Short | Type | Default | Description                   |
| --------------- | ----- | ---- | ------- | ----------------------------- |
| `--template-id` | —     | int  | —       | ID of the template to delete. |

This command deletes the template with ID `2996`:

```bash
azion delete data-stream templates --template-id 2996 -y
```

The command confirms the deletion:

```text
Template 2996 was successfully deleted
```

A template that a stream uses cannot be deleted. The command fails, and the error carries the cause `["Cannot delete a template with associated data streams."]`. To delete the template, first delete the streams that use it, or update them to use another template.

---

## Related resources

- [Global options](/en/documentation/devtools/cli/globals.md): The options every command accepts, such as `--format`, `--out`, and `-y`.
- [Stream settings](/en/documentation/platform/data-stream/stream-settings.md): Every field of the stream object, the values it takes, and the errors the API returns.
- [Templates and payload](/en/documentation/platform/data-stream/templates-and-payload.md): The variables of each preset template, and the format of a custom data set.
- [How Data Stream works](/en/documentation/platform/data-stream/how-it-works.md): The path an event follows from its data source to the endpoint.
