Reputation: 11
#EXTM3U #EXT-X-VERSION:5 #EXT-X-MEDIA:TYPE=AUDIO,URI="JKX001-mp4a_96000_eng=2.m3u8",GROUP-ID="audio-AACL-96",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="2" #EXT-X-STREAM-INF:BANDWIDTH=456455,AVERAGE-BANDWIDTH=414959,CODECS="avc1.4d4015,mp4a.40.2",RESOLUTION=480x270,FRAME-RATE=25.000,AUDIO="audio-AACL-96" JKX001-avc1_300000=1.m3u8
I need to modify the HTTP response body of the m3u8 response that I am getting when someone hits my CloudFront. From m3u8 body above, I'd like to replace "JKX001" to to other string such as "AAA". Then m3u8 response in body will be like
#EXTM3U #EXT-X-VERSION:5 #EXT-X-MEDIA:TYPE=AUDIO,URI="AAA-mp4a_96000_eng=2.m3u8",GROUP-ID="audio-AACL-96",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="2" #EXT-X-STREAM-INF:BANDWIDTH=456455,AVERAGE-BANDWIDTH=414959,CODECS="avc1.4d4015,mp4a.40.2",RESOLUTION=480x270,FRAME-RATE=25.000,AUDIO="audio-AACL-96" AAA-avc1_300000=1.m3u8
Does CloudFront function has capability to do this ?
Upvotes: 1
Views: 687
Reputation: 122
Yes, you can do this using the Lambda at Edge
feature of Cloudfront.
In essence Lambda at Edge
allows you to modify all aspects of the HTTP response at the time of the request or at the time of the response, using a Lambda function written in your language of choice. This lambda will run for EACH response, so the lambda execution cost should be considered. This is a program-it-yourself solution rather than a built-in text substitution feature.
Documentation can be found here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-at-the-edge.html
As an alternative to Lambda at Edge
, you might also consider whether it would be more practical to implement a dynamic web server that constructs the response body m3u8 using a templating approach.
Upvotes: -1