aws-samples / image-optimization

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

[Feature request] Supply original image from original S3 bucket #47

Open crank-chips opened 3 months ago

crank-chips commented 3 months ago

In the current implementation lambda function makes copy of original image fromoriginalImageBucketName to transformedImageBucket with /original prefix. Which will increase storage usage and as fact will increase the cost, since original images usually have large size. Is there a way to avoid duplication of original image and supply it directly from original S3 bucket instead?

achrafsouk commented 3 months ago

Hello,

The code can very easily changed to allow this way of working. In the code section where the image is uploaded to S3, check if the Key ends with /original, and only do the upload if the condition does not match.

However, It's a tradeoff. If you do that, you reduce the storage cost, however you add latency and cost for accessing original images on cache misses, because CloudFront will try with the generated image bucket, wont find the image, then fallback to the the Lambda, which will fetch the original image from your original S3 bucket then serve it.