Does anyone know if it's possible to use CloudFron...
# help
Does anyone know if it's possible to use CloudFront + Lambda@Edge to rewrite content served to a user? E.g. if a user accessed a file on my CDN that ends in a certain extension, a Lambda function is invoked to somehow modify that file's content before serving it to the user
This isn't possible yet because the lambda function does not have access to the body
Curious what your use case is though
Damn. I have a super complicated issue I need to solve
Actually I wonder if you can just fetch the object from inside the lambda function
Ah like you can only change the response headers at the moment
Ooh good! Yes, I was searching and figured this may be doable. Just curious if someone else has done it. I'll explain the use case when I'm not on my phone because I have to type a whole paragraph at least 😜
I was getting confused with CloudFront Functions which are much more limited
ok. so.. i’m serving up audio & video files, but as HLS format (MPEG TS chunks). an .m3u8 is served from the server, and that file contains a list of filenames (*.ts) that the browser will fetch.. typically 5-10 second chunks, and seamlessly stream them I need a way to secure those URLs. CloudFront signed cookies was the initial plan, and it worked great, until I discovered that Safari (my most hated browser) won’t let iframe’d content transmit HTTPS cookies over the wire 😕 so then I figured I’d try CloudFront signed URLs. I wrote an API endpoint that is fed to
<audio src>
which basically calls a Lambda function to grab the m3u8 file from S3, inject signed URLs, then serve that up to the browser. this works great.. introduces a little latency, sadly, but not terrible. BUT, no way this would work with video content because two m3u8 files are involved. the main one has a list of secondary m3u8 files based on the user’s bandwidth & screen size (I believe) to serve up smaller files. so now here I am 🙂 hoping that I can just set up my CloudFront CDN so that if a file ending in
is fetched, Lambda can modify the files with in to be signed URLs
ahh clever
Worst case, does the m3u8 have to be served from a cdn?
yeah. I mean, the audio one was simple enough that I could serve it from an API. but no, the video one is more complicated since the m3u8's are chained
so that has to be served from CloudFront+S3
ah I see
you’d think browsers would be smart enough to tack on a query string if one was passed to the m3u8. e.g.
and then the media files would have the same querystring
but nope, I tried that already
I hope the CloudFront/Lambda@Edge thing works like I expect. that’d be huge. it would be able to sign all URLs in the file, and also cache the m3u8 content as well. that would be great
I think I should be able to set up Lambda triggers in CloudFront using CDK/SST, yeah?
seems like cookies in iframes might be going away for all browsers at some point. one developer said:
But I am sick of doing these increasingly ugly hacks. IMO, iframes and 3rd party cookies are dead - Apple has just killed them a year or so earlier.
this thread is full of people complaining about the thing I just told you about 😄
Safari really is the new IE. So terrible
Just wanted to chime in
I think I should be able to set up Lambda triggers in CloudFront using CDK/SST, yeah?
Here’s an example ^^btw
sst start
currently doesn’t support Lambda@Edge. So the example above uses CDK’s
. Let me or @thdxr if that’s something you need.
Thanks! Probably don't need to test locally, no. It'll be deployed as a way to modify content coming from CloudFront