Rewrite Output URL
I would like to do a few things with the image that is output by SharpJS.
- I would like to change the encoded URL to be a form of the original URL with possibly changing the extension (example from jpg to webP). Is this possible? Any benefit to leaving the encoding
- I would like to change the domain fro the cloudfront domain to a custom subdomain. Is it the same setup as setting up a subdomain in Route 53 with a CNAME to the cloudfront subdomain and setting it up on cloudfront?
- (Bonus Question) Do I set the caching of the images on the cloudfront settings or somewhere else?
Thanks in advance
To go a bit further in explaining why we considered changing to a custom subdomain.
We are using a WordPress installation and we have all uploads, images, pdfs, other file types, basically the /uploads/ folder, pushed to s3 using https://github.com/humanmade/S3-Uploads (Great plugin!). This created a few issues like the need to change rules in cloudfront to skip the lambda function for everything but images.
We decided to leave the cloudfront domain in place. We did this because we are using the original file, uploaded by users, for the regular src in the image tag, which is good for SEO. We are using the generated images as srcset to help with speed so we do not care if they are on a 3rd party subdomain. This setup allows for us to take advantage of optimized/resized images for speed and still get the SEO for the images users uploaded. It also reduced complexity.
Here is a guide on how to change caching for files on cloudfront, https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html