'Persist default Cloudfront behavior cache policy on Amplify deployment

I have a NextJS webapp on AWS Amplify where I need to forward the Host header to the Lambda function. I managed to do it by setting the cache policy of the default Cloudfront behavior to the Amplify managed cache policy, but each deployment reverts the default behavior to empty legacy cache settings

Is there a way to persist the default cache policy to a managed policy on deploy? Either on deployment or with a post-deploy script



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source