HLS stream takes a long time to become available at CloudFront edge servers

I have several EC2 instances running as HTTP live origins for CloudFront distributions. I have everything configured and, for the most part, it works. I can push a stream to an origin and start watching via CloudFront usually without having to wait the first time. But if the encoder or the origin application is restarted, it often takes 3-5 minutes for the stream to become available at CloudFront’s edges again. During this time, I can pull up the stream directly from the origin, so I know that’s available, but CloudFront just doesn’t seem to see it.

Is this just the nature of using a CDN? Are there configuration settings either in Wowza or my CloudFront distribution I could look at to fix this?

To be clear: I am not referring to latency in the stream itself. I am talking about the time it takes from publishing a stream to my Wowza origin before it becomes watchable on CloudFront.

Thanks.

EDIT: I think I’ve found the problem. CloudFront caches 404 errors. If someone tries to watch the stream during the time that it is offline, the resulting 404 error will be cached in CloudFront by default for 5 minutes. To get around this, in your distribution settings, go to “Error Pages” and “Create Custom Error Response” (Don’t worry, you’re not actually creating a custom response.) Select 404 as the error type and set TTL to something small. Leave “Customize Error Response” as “No.” (Unless you do want a custom response, in which case, ignore my previous parenthetical statement.)

Still todo: Now I just need to figure out how to stop “x-cache: RefreshHit from cloudfront” for chunklist_*.m3u8 after the encoder restarts.

Hi Kyle - Did you end up answering your own question completely? I see you called out a remaining todo item, but I’m not sure its a Wowza related item.

Well, I had just typed out a much more detailed response, but I lost it when I went to post. The short version is I worked around it, but I think the origin is erroneously, either through a bug or my own configuration error, returning “HTTP 304 Not Changed” for chunklist_*.m3u8 files after an encoder has been restarted. I worked around it by creating a custom behavior on Cloudfront to set the TTL for *.m3u8 files to only a few seconds. I have configured my application to act as a live origin and the cache-control headers are being set.

                <LiveStreamPacketizer>
                        <!-- Properties defined here will override any properties defined in conf/LiveStreamPacketizers.xml for any LiveStreamPacketizers loaded by this applications -->
                        <Properties>
                                <Property>
                                        <Name>cupertinoCreateAudioOnlyRendition</Name>
                                        <Value>true</Value>
                                        <Type>Boolean</Type>
                                </Property>
                                <Property>
                                        <Name>httpRandomizeMediaName</Name>
                                        <Value>true</Value>
                                        <Type>Boolean</Type>
                                </Property>
                        </Properties>
                </LiveStreamPacketizer>
                <HTTPStreamer>
                        <!-- Properties defined here will override any properties defined in conf/HTTPStreamers.xml for any HTTPStreamer loaded by this applications -->
                        <Properties>
                                <Property>
                                        <Name>httpOriginMode</Name>
                                        <Value>on</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>cupertinoCacheControlPlaylist</Name>
                                        <Value>max-age=1</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>cupertinoCacheControlMediaChunk</Name>
                                        <Value>max-age=3600</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>smoothCacheControlPlaylist</Name>
                                        <Value>max-age=1</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>smoothCacheControlMediaChunk</Name>
                                        <Value>max-age=3600</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>smoothCacheControlDataChunk</Name>
                                        <Value>max-age=3600</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>smoothStreamingEncryptionRandomIV</Name>
                                        <Value>false</Value>
                                        <Type>Boolean</Type>
                                </Property>
                                <Property>
                                        <Name>sanjoseCacheControlPlaylist</Name>
                                        <Value>max-age=1</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>sanjoseCacheControlMediaChunk</Name>
                                        <Value>max-age=3600</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>sanjoseCacheControlPlaylist</Name>
                                        <Value>max-age=1</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>sanjoseCacheControlMediaChunk</Name>
                                        <Value>max-age=3600</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>mpegdashCacheControlPlaylist</Name>
                                        <Value>max-age=1</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>mpegdashCacheControlMediaChunk</Name>
                                        <Value>max-age=3600</Value>
                                        <Type>String</Type>
                                </Property>
                                <Property>
                                        <Name>cupertinoUserHTTPHeaders</Name>
                                        <Value>Access-Control-Allow-Origin: *</Value>
                                </Property>
                        </Properties>
                </HTTPStreamer>