
Delivering Live Video on AWS: MediaConnect, MediaLive and MediaPackage with Terraform
From SRT feed to player: how to build a live video chain with MediaConnect, MediaLive and MediaPackage v2, with real-world patterns and ready-to-use Terraform.
Why a managed live chain
Three AWS Elemental services cover the full path from a camera feed to a viewer's player: MediaConnect transports the contribution signal, MediaLive encodes it into an adaptive bitrate (ABR) ladder, and MediaPackage packages and protects it for delivery through CloudFront. The contribution encoders stay on premises at the venue or in the production facility. Everything after them (IP gateways, ABR transcoders and packagers) moves into a chain you deploy in minutes and pay for by the hour.
This article is written for broadcast and media engineers who know SDI and IP workflows and want a production-grade pattern on AWS. You get three things: the reference architecture with the design choices behind each hop, real-world patterns and a Terraform deployment you can apply as-is and extend.
Reference architecture
The chain has four hops and, in production, two of everything up to the packager: two contribution feeds, two MediaConnect flows (or router outputs) and two MediaLive pipelines, each in its own Availability Zone. MediaPackage v2 is where the two paths merge into one set of manifests, and CloudFront is the only thing viewers ever talk to.
Venue Contribution Encoding Packaging Delivery Encoder A ---> Flow A ---> Pipeline 0 ---+SRT line 1 SRT listener, AZ a AZ a, ABR ladder | +-> MediaPackage v2 --> CloudFrontEncoder B ---> Flow B ---> Pipeline 1 ---+ 2 ingest URLs OAC, cacheSRT line 2 SRT listener, AZ b AZ b, ABR ladder CMAF origin | HLS + DASH v Players Router mode: one router input, one take per pipeline outputEach pipeline pushes to its own MediaPackage ingest endpoint; if one stalls, the origin keeps serving from the other without the player noticing.
Contribution: MediaConnect flows or the router
Use a flow when one source feeds a fixed set of destinations; use the router when sources and destinations change during the day and someone needs to switch between them. Both are MediaConnect, both accept the usual contribution protocols, and they can be combined.
Flows are the classic building block: one source (or a failover pair), up to 50 outputs, entitlements to share the signal with other AWS accounts. A flow lives in one Availability Zone, so a redundant design uses two flows in two AZs, one per MediaLive pipeline. MediaLive attaches to flows natively: a MediaLive input of type
MEDIACONNECT takes up to two flow ARNs, and MediaLive creates the flow outputs itself and places its pipelines in the same AZs as the flows [1].The MediaConnect router went GA on 19 November 2025 [8] and brings the broadcast-router model to the cloud: independent inputs and outputs that you connect in any combination at runtime [2]. A "take" assigns an input to an output, exactly like an X/Y panel. Router inputs can be standard (RTP, RIST, SRT caller or listener), failover, merge (packet-level merging of two sources) or fed from a flow; router outputs can be standard, feed a flow, or feed a MediaLive input directly [3]. Routing can be regional or global, and AWS states fixed end-to-end latency within and across Regions [4], so a feed ingested in Frankfurt can be taken in Dublin without a second contribution link.
| Flow | Router |
|---|---|---|
Mental model | A fixed transport pipe | An X/Y routing matrix |
Switching | Edit or recreate outputs | TakeRouterInput on an output, no reconfiguration |
Scope | One Region, one AZ per flow | Regional or global routing |
Redundancy | Failover source, two flows in two AZs | Failover and merge inputs, cross-Region routes |
Sizing | Per flow and per GB out | Input and output tiers ( INPUT_20/50/100 , OUTPUT_20/50/100 ), hourly per active I/O |
MediaLive hand-off | Input type MEDIACONNECT | Input type MEDIACONNECT_ROUTER |
Terraform today | awscc_mediaconnect_flow | CloudFormation resources ( AWS::MediaConnect::Router* ), wrapped in Terraform |
Whichever you choose, three design rules hold:
- Protocol: SRT is the default for internet contribution; use Zixi where the venue already runs it, RIST where vendors require it, and RTP with FEC only on private links (Direct Connect, VPC).
- Access: never open a listener to
0.0.0.0/0. Restrict the flow source's whitelist CIDR or the router network interface's allow rules to the venue's egress IPs, and encrypt SRT with a passphrase from Secrets Manager.
- Redundancy: two contribution paths from the venue (two encoders or two ISPs) into two AZs. A single flow with a failover source protects against a lost link, not against a lost AZ.
Encoding: MediaLive
Run a
STANDARD channel for anything with an audience: two pipelines in two AZs, each fed by its own contribution path, each pushing to its own MediaPackage ingest endpoint. SINGLE_PIPELINE halves the encoder cost and is fine for rehearsals, internal feeds and the test stack in this article's Terraform (switchable with one variable).Inputs. The input type follows the contribution choice:
MEDIACONNECT with two flow ARNs, or MEDIACONNECT_ROUTER , which needs no MediaConnect setup step at all: creating the input makes it appear in the router as a destination [5], one per pipeline AZ. Add a second input and an automatic input failover pair when the venue sends a backup feed that should take over on black, silence or loss of signal.ABR ladder. Start with four or five renditions and tune from real viewer data. A sensible broadcast starting point for 1080p50 sports content:
Rendition | Resolution | Video bitrate | Codec settings |
|---|---|---|---|
1080p | 1920×1080 | 6.0 Mbit/s | H.264 High, QVBR quality 8, GOP 2 s |
720p | 1280×720 | 3.5 Mbit/s | H.264 High, QVBR quality 7, GOP 2 s |
540p | 960×540 | 2.0 Mbit/s | H.264 Main, QVBR quality 7, GOP 2 s |
360p | 640×360 | 0.8 Mbit/s | H.264 Main, QVBR quality 6, GOP 2 s |
Audio | AAC-LC stereo | 128 kbit/s | 48 kHz |
Keep the frame rate of the source (50 fps in Europe) on the upper rungs; sports at 25 fps looks noticeably worse. Use QVBR with a max bitrate rather than CBR: it saves egress on static shots and spends bits on fast motion. Align the GOP to the segment length (2 s GOP, 4 s or 6 s segments; 1 s or 2 s for low latency) so every segment starts on an IDR frame.
Output to MediaPackage v2. Use an HLS output group with two destinations, the two MediaPackage v2 ingest URLs. No credentials are needed for the MediaLive-to-MediaPackage v2 push [6]. Set the HTTP dialect to basic PUT, TS segments, and a short segment length if you want low latency downstream.
Operations hooks. Turn on the channel schedule for SCTE-35 ad markers and input switches, and send pipeline alerts to EventBridge. MediaLive bills per running hour per pipeline, so idle channels must be stopped, not left running (see Operations).
Packaging: MediaPackage v2
Use MediaPackage v2 for new builds: one ingest, CMAF segments, and HLS, Low-Latency HLS and DASH manifests generated from the same segments. Its resource model has three levels:
- Channel group – a namespace and the egress domain, typically one per environment or business unit.
- Channel – one per live service. It exposes two ingest endpoints, one per MediaLive pipeline, and handles pipeline redundancy on its own: if one pipeline stalls, the endpoints keep serving from the other. Even a two-pipeline MediaLive channel needs only one MediaPackage channel [6].
- Origin endpoint – one per packaging profile. A single CMAF endpoint can carry an HLS manifest and a DASH manifest at the same time, so most services need just one endpoint, plus a second one only for a different DRM or latency profile. Settings that matter in production:
Setting | Recommended value | Why |
|---|---|---|
Container | CMAF | One segment set for HLS and DASH halves origin storage and CDN cache misses |
Segment duration | 4 s (2 s for low latency) | Must be a multiple of the encoder GOP |
Manifest window | 60 s | Short playlists for live players; time-shift uses the startover window instead |
Startover window | 2–6 h | Enables start-over, catch-up and live-to-VOD harvest jobs |
Program date time | Every 60 s | Lets players and analytics sync to wall-clock time |
Encryption | SPEKE v2 with your DRM provider | Widevine/PlayReady for DASH, FairPlay for HLS, from one endpoint |
CloudFront in front, always. Players never hit MediaPackage directly. Put a CloudFront distribution in front of the origin endpoint and lock the endpoint down with origin access control [7]: an OAC of origin type
mediapackagev2 signs CloudFront's requests, and the endpoint policy allows mediapackagev2:GetObject and mediapackagev2:GetHeadObject only for the cloudfront.amazonaws.com principal with your distribution's ARN as AWS:SourceArn . This replaces the old pattern of public endpoints protected by IP allow lists or shared secrets in headers.Cache manifests for about half a segment duration and segments for a day; use the AWS managed cache policy for Elemental MediaPackage or an equivalent that forwards the query strings players use for time-shift (
start , end , aws.manifestfilter ).Real-world patterns
The same three services appear in very different projects; what changes is where the switching happens and who owns the AWS account. Three patterns from live sports and public broadcasting, with names removed.
1. League-wide feed distribution
A top-tier football league distributes every match feed from the stadiums to domestic and international rights holders. Each stadium sends two SRT feeds over separate lines. The distribution layer is pure MediaConnect: the feeds land on inputs, and each rights holder receives an output (SRT, Zixi or an entitlement into their own AWS account). MediaLive and MediaPackage are used only for a secondary path: a low-bitrate HLS proxy of every match for monitoring, compliance and the league's own editorial tools.
- Why the router fits: the source-to-destination mapping changes every match day. With flows, that mapping is rewritten as configuration; with the router, it is a set of takes that an orchestration layer or an operator executes against a fixed pool of inputs and outputs.
- Lesson: keep transport and encoding decoupled. Rights holders want the contribution-quality feed, not your ABR ladder.
2. Public broadcaster cloud production
A public broadcaster produces sports and event coverage in the cloud and runs the platform in its own AWS account. MediaConnect brings in the camera and commentary feeds; cloud production tools (vision mixing, graphics, audio) sit between MediaConnect and MediaLive; the programme output goes through MediaLive and MediaPackage to the broadcaster's player and to linear playout.
- Why IaC matters here: the whole chain is deployed per production and torn down afterwards. A production that exists for six hours should cost six hours, and the next one should come up identical.
- Lesson: design the IaC for the customer's account from day one: cross-account roles, no hard-coded account IDs, tagging that their FinOps team can read.
3. Pop-up channels for events
A sports federation streams tournaments as temporary OTT channels: one channel per court or pitch, live for a weekend, then archived. Each channel is one instance of the stack in this article: one flow (or router input), a single-pipeline MediaLive channel, a MediaPackage channel with a 6-hour startover window, and a shared CloudFront distribution.
- Why it works: the marginal cost of another court is one more stack, started by schedule and stopped after the final whistle.
- Lesson: most of the bill is MediaLive running hours. Automate start and stop before you optimize anything else.
The Terraform deployment
One
terraform apply builds the full chain in a stopped state; scripts/start.sh brings it live and scripts/stop.sh stops the billing. Two variables switch the architecture: ingest_mode ( flow or router ) and channel_class ( SINGLE_PIPELINE or STANDARD ).It uses two providers:
hashicorp/aws for MediaLive, CloudFront, IAM and monitoring, and hashicorp/awscc (generated from the CloudFormation registry) for MediaConnect flows and MediaPackage v2. The router resources are newer than both, so router mode wraps them in a small CloudFormation stack inside Terraform; swap it for native resources once your provider version ships them.File | What it creates |
|---|---|
mediaconnect_flow.tf | One SRT-listener flow per pipeline AZ, optional SRT passphrase from Secrets Manager, MediaLive input of type MEDIACONNECT |
mediaconnect_router.tf | Router network interface, SRT-listener router input, one router output per pipeline, MediaLive input of type MEDIACONNECT_ROUTER |
medialive.tf | Channel with the ABR ladder from var.renditions , HLS output group to both MediaPackage ingest URLs |
mediapackage.tf | Channel group, channel, CMAF origin endpoint (HLS + DASH, start-over), endpoint policy for CloudFront only |
cloudfront.tf | Distribution with OAC of type mediapackagev2 and the managed MediaPackage cache policy |
iam.tf , monitoring.tf | MediaLive role; EventBridge rule routing MediaLive and MediaConnect alerts to SNS |
scripts/start.sh , stop.sh | Start/stop flows or router I/Os (including the take) and the MediaLive channel |
The key pieces
The flow is a few lines. Its AZ follows the pipeline, so MediaLive lands each pipeline next to its flow:
resource "awscc_mediaconnect_flow" "this" { count = var.ingest_mode == "flow" ? local.pipeline_count : 0 name = "${var.name}-flow-${count.index}" availability_zone = local.pipeline_azs[count.index] source = { name = "srt-in-${count.index}" protocol = "srt-listener" ingest_port = var.srt_port min_latency = var.srt_min_latency_ms whitelist_cidr = var.allowed_source_cidr }}In router mode, the router output points at the MediaLive input and pipeline; the take that connects it to the router input is an operation, not configuration, so it runs in
start.sh :"RouterOutput${i}" => { Type = "AWS::MediaConnect::RouterOutput" Properties = { Name = "${var.name}-to-medialive-${i}" RoutingScope = "REGIONAL" Tier = var.router_tier.output MaximumBitrate = var.router_max_bitrate_bps AvailabilityZone = az Configuration = { MediaLiveInput = { MediaLiveInputArn = { "Fn::GetAtt" = ["MediaLiveInput", "Arn"] } MediaLivePipelineId = "PIPELINE_${i}" DestinationTransitEncryption = { EncryptionKeyType = "AUTOMATIC" EncryptionKeyConfiguration = { Automatic = {} } } } } }}The MediaLive destination takes the MediaPackage ingest URLs directly, one per pipeline:
destinations { id = "mediapackage" dynamic "settings" { for_each = local.mediapackage_ingest_urls # awscc_mediapackagev2_channel.this.ingest_endpoint_urls content { url = settings.value } }}The origin endpoint policy is what keeps viewers off the origin:
policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = { Service = "cloudfront.amazonaws.com" } Action = ["mediapackagev2:GetObject", "mediapackagev2:GetHeadObject"] Resource = awscc_mediapackagev2_origin_endpoint.cmaf.arn Condition = { StringEquals = { "AWS:SourceArn" = aws_cloudfront_distribution.this.arn } } }]})Deploy and test
- Copy
terraform.tfvars.exampletoterraform.tfvarsand setallowed_source_cidrto your encoder's public IP.
- Run
terraform initandterraform apply. Nothing bills by the hour yet: the channel is created withstart_channel = false, flows and router I/Os in standby.
- Run
./scripts/start.sh. It starts the ingest side, performs the router take in router mode, starts the channel and prints the SRT endpoint and the playback URL.
- Send a test signal; without a hardware encoder, ffmpeg with libsrt does the job:
ffmpeg -re -f lavfi -i testsrc2=size=1920x1080:rate=50 \ -f lavfi -i sine=frequency=1000:sample_rate=48000 \ -c:v libx264 -preset veryfast -b:v 8M -g 100 -pix_fmt yuv420p \ -c:a aac -b:a 192k -f mpegts \ "srt://<ingest-ip>:5000?mode=caller&latency=2000000"- Open
terraform output -raw playback_hlsin Safari, VLC or an hls.js demo page. Expect the first segments after about 20–30 seconds.
- Run
./scripts/stop.shwhen you are done, andterraform destroyto remove everything. The complete code lives in the GitHub repositoryPatrickFfm93/AWS-Terraform-Media-Pipelines[12]: clone it, set your values interraform.tfvarsand apply. The HCL is syntax-checked but has not been applied against a live account in this draft, so run it in a sandbox account first.
Operations: monitoring, cost and security
A live chain fails at the edges: the contribution link and the player. Watch those first, and make starting and stopping the chain a scripted, scheduled action.
Monitoring. The deployment routes
MediaLive Channel Alert and MediaConnect Alert events to SNS. On top of that, alarm on four signals:Signal | Service | Why |
|---|---|---|
Source disconnections, packet loss, recovered packets | MediaConnect | First sign of a bad contribution link; rising recovered packets warn before the picture breaks |
Input video frame rate, active alerts per pipeline | MediaLive | Detects black, frozen or missing input on one pipeline while the other still runs |
Ingress and egress bytes, 4xx/5xx on the endpoint | MediaPackage v2 | Confirms segments arrive and the origin serves them |
5xx error rate, cache hit ratio | CloudFront | What viewers actually experience |
Flow thumbnails (enabled in the Terraform) and MediaLive's confidence monitoring give operators a picture without opening a player.
Cost. MediaLive is billed per running pipeline hour and dominates the bill for most events; a
STANDARD channel costs two pipelines. MediaConnect adds an hourly fee per flow or per active router I/O (tiered by bitrate) plus data transfer out; MediaPackage and CloudFront scale with viewers. Three habits keep it under control:- Stop channels and flows between events; schedule
start.shandstop.shwith EventBridge Scheduler or from your orchestration layer.
- Use
SINGLE_PIPELINEfor rehearsals and internal feeds,STANDARDonly for the on-air window.
- Tag every resource (
Project,Event,CostCenter) so each production shows up as its own line in Cost Explorer. Security. Restrict SRT listeners to known CIDRs and encrypt SRT with a passphrase from Secrets Manager. Keep the MediaPackage endpoint behind OAC so the only public surface is CloudFront; add CloudFront signed URLs or a token check at the edge for paid content, and SPEKE-based DRM where rights holders require it. Give MediaLive and MediaConnect roles only the actions they use, as the IAM policy in the repository does.
Lessons learned
The services are the easy part; the decisions around them decide whether a live chain survives a match day. Five that held across every project:
- Decide where switching lives. Static paths belong in flows; anything an operator or scheduler changes during the day belongs in the router.
- Redundancy is end to end. Two pipelines are worth little if both are fed by the same encoder over the same line.
- Align GOP, segment and manifest timing across MediaLive and MediaPackage before tuning anything else; most playback stalls trace back to a mismatch here.
- Infrastructure as code is the operating model, not documentation. If a production cannot be created and destroyed by a pipeline, it will drift.
- Stopped is the default state. The cheapest live channel is the one that is not running.
Start with the Terraform in flow mode and
SINGLE_PIPELINE, send the ffmpeg test signal, then switch toSTANDARDand router mode once the basic chain plays.
Sources
- Create a MediaConnect input – MediaLive User Guide: https://docs.aws.amazon.com/medialive/latest/ug/setup-input-emx.html
- MediaConnect Router feature page – AWS: https://aws.amazon.com/mediaconnect/features/router
- RouterOutput – MediaConnect API Reference: https://docs.aws.amazon.com/mediaconnect/latest/api/API\_RouterOutput.html
- Using the MediaConnect router – MediaConnect User Guide: https://docs.aws.amazon.com/mediaconnect/latest/ug/using-mediaconnect-router.html
- Create a MediaConnect Router input – MediaLive User Guide: https://docs.aws.amazon.com/medialive/latest/ug/setup-input-mediaconnect-router.html
- HLS output group to MediaPackage v2 – MediaLive User Guide: https://docs.aws.amazon.com/medialive/latest/ug/origin-server-hls-empv2.html
- Restricting access to a MediaPackage v2 origin – CloudFront Developer Guide: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-mediapackage.html
- AWS announces Elemental MediaConnect Router – What's New, 19 Nov 2025: https://aws.amazon.com/about-aws/whats-new/2025/11/elemental-mediaconnect-router
- Build redundant live video workflows with MediaConnect Router – AWS for M&E Blog: https://aws.amazon.com/blogs/media/build-redundant-live-video-workflows-with-aws-elemental-mediaconnect-router/
- TakeRouterInput – AWS SDK for Python (Boto3) reference: https://docs.aws.amazon.com/botocore/latest/reference/services/mediaconnect/client/take\_router\_input.html
- AWS::MediaConnect::RouterInput – CloudFormation Template Reference: https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-mediaconnect-routerinput.md
- AWS-Terraform-Media-Pipelines – Terraform code for this article on GitHub: https://github.com/PatrickFfm93/AWS-Terraform-Media-Pipelines
#aws-elemental-mediaconnect#aws-elemental-medialive#aws-elemental-mediapackage#media-services#aws-community-builders
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article