Great news - or should I say old news!?
Apparently Amazon CloudFront have added support for query string forwarding for custom origin distributions. This feature was announced approximately two weeks after I had written this lengthy blog post on how to mitigate this deficiency when using CloudFront and Sitecore with dynamic media URLs.
With the introduction of query string forwarding you can you can drop all the rewriting and just set the Media.MediaLinkPrefix (or do something slightly more elegant). Remember to configure the cache HTTP headers for Sitecore media:
<!-- allow proxies to cache --> <setting name="MediaResponse.Cacheability" value="public" /> <!-- lifetime 12 hours --> <setting name="MediaResponse.MaxAge" value="0.12:00:00:00" />
The last thing to do is to go to the AWS management console and edit the behaviour setting on your custom origin CloudFront distribution to ensure query string forwarding is enabled.
This set-up is a lot lower in complexity than my initial post and it is much more in line with what I initially had hoped for when I started researching using CloudFront with Sitecore. This approach does not have any considerations around edge cache invalidation (cache beyond time-out) - this would probably need to be addressed production use.