aws-samples / image-optimization

Simple, performant and cost efficient solution for optimizing images using Amazon CloudFront, Amazon S3 and AWS Lambda
MIT No Attribution
172 stars 106 forks source link

Pass through for non-images? #12

Closed mcmanimie closed 11 months ago

mcmanimie commented 11 months ago

Can this be set up so that, in the event of a request for a non-image (.pdf for example), it simply grabs it from the bucket without attempting to optimize. As it stands I have a lot of scattered content in my primary bucket and my entire Wordpress instance, leveraging WP Offload Media, pulls through the same CDN address so when I request .pdf's and the like I get an Internal Server Error.

achrafsouk commented 11 months ago

It depends on how you identify your image or non image files. This can be done by creating CloudFront cache behaviours with different configurations. For example, keep the default cache behaviour as is for image transformations, and create a new cache behaviour catching .pdf extensions with a simple configuration pointing to the bucket containing pdf files.

mcmanimie commented 11 months ago

Got it! So add my primary S3 bucket to the ImageTransformation distribution (which currently only has origins with the Lambda function and ImageTransformation bucket), create a catch behavior which filters out .pdf, and point to it?

achrafsouk commented 11 months ago

yes thats an easy solution, let me know if it works

mcmanimie commented 11 months ago

Boom! Easy peasy. Seems to work fine. If .pdf, right to the bucket, everything else routes to Lambda.

achrafsouk commented 11 months ago

awesome