I'm running a CloudFront distribution, which has a Lambda@Edge function running on it.
I'd like to manipulate the DOM of the page that CloudFront is in front of. Specific example: add a custom script to the page inside the head.
On Cloudflare this can be done easily in a worker (roughly equivalent product) using their HTMLRewriter class.
How can I do this on AWS CloudFront?
My working theory is:
- Observe the request for the HTML page
- Do some kind of manipulation of the body of the response - parse it into the DOM object and manipulate as needed
I haven't managed to get this working yet. Interested in other approaches or if I'm missing something obvious.