---
name: azion-deliver-a-live-stream-from-live-ingest
description: >-
  Create a Live Ingest connector in the region of your encoder, and send the viewers' requests of an application to it with a rule.
---

# Deliver a live stream from Live Ingest

You create the connector that takes a live stream into Azion, and the rule that delivers that stream to viewers, from Azion Console, the Azion API, or the Azion CLI. For an HLS stream that your own origin produces, refer to [Enforce HLS cache for live streaming](/en/documentation/guides/media-and-streaming/streaming/enforce-hls-cache/).

Your encoder pushes the stream over RTMP to [Live Ingest](/en/documentation/platform/connectors/live-ingest/ingestion-and-delivery/), which converts it to HLS: a playlist, `.m3u8`, and the segments it lists, `.ts`. Viewers never reach Live Ingest directly. They request the stream from an application, and a rule of that application names the connector.

```mermaid
%%{init: {"layout": "dagre", "themeVariables": {"fontSize": "13px"}, "flowchart": {"nodeSpacing": 12, "rankSpacing": 12, "padding": 6, "wrappingWidth": 70, "minNodeWidth": 40, "useMaxWidth": true}}}%%
flowchart TD
  Encoder["Encoder"] -->|"RTMP to the region of the connector"| LI["Live Ingest converts the stream to HLS"]
  LI --> Connector["connector of type live_ingest"]
  Player["Viewer's player"] -->|"HTTPS request"| Rule["application rule: Set Connector"]
  Rule --> Cache["Enforce HLS cache: playlist 5 seconds, segment 60 seconds"]
  Cache -->|"miss or expired copy"| Connector
  Cache -->|"valid copy"| Player
```

1. The encoder pushes the stream over RTMP to Live Ingest, in the region of the connector.
2. Live Ingest converts the stream to HLS.
3. A viewer's player requests the stream from the application, and a rule's *Set Connector* behavior names the connector.
4. Azion adds the *Enforce HLS cache* behavior to that rule, which caches each playlist for 5 seconds and each segment for 60 seconds.
5. A valid cached copy answers every viewer, and only an expired or missing copy is fetched through the connector.

---

## Prerequisites

- An application served by a workload, with a hostname that viewers request. To create both, refer to [Applications quickstart](/en/documentation/platform/applications/quickstart/).
- An encoder that pushes RTMP with username and password authentication. Azion provides the credentials and the ingest URLs of a primary and a backup endpoint. For the requirement, refer to [Ingestion](/en/documentation/platform/connectors/live-ingest/ingestion-and-delivery/#ingestion).
- A [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/), for the API procedures.
- The [Azion CLI](/en/documentation/devtools/cli/) installed and authorized, for the CLI procedures.
- Access to Azion Console, for the Console procedures. Refer to [Access Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).

This guide does not cover how you obtain the ingest URLs and credentials, or the URL layout of the playlist that viewers request. The examples use `my-live-connector` for the connector and `us-east-1` for the region. Replace them with your values.

---

## Create the Live Ingest connector

The connector carries one setting, the region where Live Ingest receives the stream. Choose the region closest to the encoder, not to the viewers: it shortens the path the stream travels before Azion receives it. The region accepts `us-east-1`, `us-east-2`, `br-east-1`, `br-east-2`, and `br-east-3`.

**Console**

To create the connector in Azion Console:

1. **Open the Connectors page**

   Access [Azion Console](https://console.azion.com/) > **Connectors**.

2. **Start a new connector**

   The **Create Connector** page opens.

3. **Name the connector**

   In **General**, enter `my-live-connector` as the **Name**.

4. **Select the Live Ingest type**

   In **Connector Type**, select *Live Ingest*.

5. **Select the region**

   In **Region**, select `us-east-1`. The field is required.

6. **Select Create**

The `my-live-connector` connector exists in your account in `us-east-1`.

**API**

To create the connector, send its name, its type, and its region to the connectors endpoint:

```bash
curl --request POST \
  --url https://api.azion.com/v4/workspace/connectors \
  --header 'Authorization: Token <personal-token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "my-live-connector",
  "type": "live_ingest",
  "attributes": { "region": "us-east-1" }
}'
```

The API answers `202` with `"state": "pending"`, and the connector reads back with `"attributes": {"region": "us-east-1"}`. Record its `id`: the rule names the connector by it. A request without `region` fails with `10059`, and a region outside the five values fails with `10039`.

**CLI**

To create the connector with the Azion CLI, save its body as `connector.json`:

```json
{
  "name": "my-live-connector",
  "type": "live_ingest",
  "attributes": { "region": "us-east-1" }
}
```

Create the connector from the file. The command needs `--type` even when the file names the type:

```bash
azion create connector --type live_ingest --file connector.json
```

The output carries the ID of the new connector, which the rule names:

```text
Created Connector with ID <connector-id>
```

The connector exists in your account, and no viewer request reaches it until a rule of the application names it. A change to a connector reaches Azion's distributed infrastructure in several minutes.

---

## Send the viewers' requests to the connector

A Request Phase rule with the *Set Connector* behavior sends the requests it matches to the connector. On an application that serves only the stream, the rule matches every path: `${uri}` starts with `/`. When several matching rules carry *Set Connector*, only the last one runs, so keep this rule after any rule that sends every path to another connector. A new rule goes after the rules the application already has.

**Console**

To create the rule in Azion Console:

1. **Open the application**

   Access [Azion Console](https://console.azion.com/) > **Applications**, and select the application that delivers the stream.

2. **Select the Rules Engine tab**

3. **Select + Rule**

4. **Name the rule**

   In **General**, enter `send-to-live-ingest` as the **Name**.

5. **Select the request phase**

   In **Phase**, select *Request Phase*.

6. **Set the criterion**

   Under **Criteria**, select the variable `${uri}` and the operator `starts_with`, and enter `/` as the argument.

7. **Select the Set Connector behavior**

   Under **Behaviors**, select *Set Connector*.

8. **Select the Live Ingest connector**

   In **Connector**, select `my-live-connector`. Azion adds the *Enforce HLS cache* behavior to the rule.

9. **Select Save**

The rule appears in the **Rules Engine** tab, under the **Request** heading.

**API**

To create the rule, send it to the Request Phase rules of the application. Replace `<connector-id>` with the `id` of the connector:

```bash
curl --request POST \
  --url https://api.azion.com/v4/workspace/applications/<application-id>/request_rules \
  --header 'Authorization: Token <personal-token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "send-to-live-ingest",
  "active": true,
  "criteria": [[{ "variable": "${uri}", "conditional": "if", "operator": "starts_with", "argument": "/" }]],
  "behaviors": [{ "type": "set_connector", "attributes": { "value": <connector-id> } }]
}'
```

The API answers `202` with a `state` of `pending` and the rule as the platform stored it. *Enforce HLS cache* has no API `type` to send, because Azion adds it to the rule.

**CLI**

To create the rule with the Azion CLI, keep it in a file, because on a command line the shell would expand `${uri}`. Save this body as `rule.json`, and replace `<connector-id>` with the ID of the connector:

```json
{
  "name": "send-to-live-ingest",
  "active": true,
  "criteria": [[{ "variable": "${uri}", "conditional": "if", "operator": "starts_with", "argument": "/" }]],
  "behaviors": [{ "type": "set_connector", "attributes": { "value": <connector-id> } }]
}
```

Create the rule in the request phase of the application:

```bash
azion create rules-engine --application-id <application-id> --phase request --file rule.json
```

The output carries the ID of the new rule:

```text
Created Rules Engine with ID <rule-id>
```

Every request of the application now reaches the stream through the connector, under the live HLS cache policy. A new rule can take a few minutes to propagate.

---

## Keep the cache of the stream to Enforce HLS cache

*Enforce HLS cache* bypasses the cache settings of the application and applies the cache policy Azion defines for live HLS. A cache setting that a *Set Cache Policy* behavior applies to these requests therefore has no effect, so do not add one. To confirm the rule carries the policy:

1. **Open the Rules Engine tab of the application**

   Access [Azion Console](https://console.azion.com/) > **Applications**, select the application, and select the **Rules Engine** tab.

2. **Open the send-to-live-ingest rule**

3. **Read the behaviors**

   The rule carries *Set Connector*, naming `my-live-connector`, and *Enforce HLS cache*.

The application caches each playlist for 5 seconds and each segment for 60 seconds. One cached copy of a segment answers every viewer who requests it in that time, so a large audience does not send each of its requests to Live Ingest.

> **Note**
>
> Live Ingest is billed on Data Ingestion, the volume of stream data that Azion ingests, and a test transmission is ingested like a real one. For the rate, refer to [Pricing](/en/documentation/fundamentals/pricing/#live-ingest).

---

## Next steps

- [Ingestion and delivery](/en/documentation/platform/connectors/live-ingest/ingestion-and-delivery.md): How Live Ingest takes the stream in a region, and how the application delivers it.
- [Connectors best practices](/en/documentation/platform/connectors/best-practices.md#live-ingest): Redundant endpoints, encoder settings, player fallback, alerts, and a load test before the event.
- [Query Live Ingest connected users](/en/documentation/guides/platform/observability/query-connected-users-data-with-graphql.md): Count the unique sessions of the stream per host, during and after the event.
- [Stream live events to large audiences](/en/documentation/use-cases/deliver-media-and-streaming/stream-live-events-to-large-audiences.md): A live event delivered from Live Ingest to a large audience, with its values and checks.
