Deliver a live stream from Live Ingest
Create a Live Ingest connector in the region of your encoder, and send the viewers' requests of an application to it with a rule.
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.
Your encoder pushes the stream over RTMP to Live Ingest, 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.
- The encoder pushes the stream over RTMP to Live Ingest, in the region of the connector.
- Live Ingest converts the stream to HLS.
- A viewer’s player requests the stream from the application, and a rule’s Set Connector behavior names the connector.
- Azion adds the Enforce HLS cache behavior to that rule, which caches each playlist for 5 seconds and each segment for 60 seconds.
- A valid cached copy answers every viewer, and only an expired or missing copy is fetched through the connector.
Prerequisites
Console
- An application served by a workload, with a hostname that viewers request. To create both, refer to 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.
- Access to Azion Console. Refer 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:
Access Azion Console > Connectors.
The Create Connector page opens.
In General, enter my-live-connector as the Name.
In Connector Type, select Live Ingest.
In Region, select us-east-1. The field is required.
The my-live-connector connector exists in your account in us-east-1.
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.
In the Stream live events to large audiences use case, this section takes these values:
| Setting | Value |
|---|---|
| Name | live-ingest-br, which the delivery rule selects |
| Type | Live Ingest, live_ingest in the API |
| Region | br-east-1, the region closest to the venue |
The connector exists in your account in br-east-1, and no viewer request reaches it until a rule of the application names it.
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:
Access Azion Console > Applications, and select the application that delivers the stream.
In General, enter send-to-live-ingest as the Name.
In Phase, select Request Phase.
Under Criteria, select the variable ${uri} and the operator starts_with, and enter / as the argument.
Under Behaviors, select Set Connector.
In Connector, select my-live-connector. Azion adds the Enforce HLS cache behavior to the rule.
The rule appears in the Rules Engine tab, under the Request heading.
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.
In the Stream live events to large audiences use case, this section takes these values:
| Setting | Value |
|---|---|
| Name | live - send to Live Ingest, in the Request Phase |
| Criterion | ${uri} starts with /, because the application on live.example.com serves only the stream |
| Behavior | Set Connector, naming live-ingest-br |
The rule carries Set Connector and Enforce HLS cache.
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:
Access Azion Console > Applications, select the application, and select the Rules Engine tab.
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.
In the Stream live events to large audiences use case, expect:
- The delivery rule carries the live cache policy. The
live - send to Live Ingestrule in the Rules Engine tab carries Set Connector, naminglive-ingest-br, and Enforce HLS cache.
Confirm that the stream answers from cache
Run these requests while the encoder is streaming. Each sends the Pragma: azion-debug-cache header, which makes the response carry the x-cache header. The examples use live.example.com for the hostname that viewers request. Replace it, <stream>, and <segment> with your values.
Request the playlist twice within 5 seconds:
The second response carries x-cache: HIT. The first can carry MISS, while the application fetches the playlist through the connector.
Take the name of a segment from the playlist body, and request it twice within 60 seconds:
The second response carries x-cache: HIT. For how to read the header, refer to Check the cache status of a response.
These checks confirm the Stream live events to large audiences use case.
In the Stream live events to large audiences use case, expect:
- Viewers can play the stream. Load
https://live.example.com/<stream>.m3u8in an HLS player, such as the hls.js configuration in Connectors best practices. The player starts the stream and keeps advancing as the encoder pushes it.