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

Deleting cached resizing images #42

Closed RahulBirCodes closed 1 month ago

RahulBirCodes commented 1 month ago

Hi!

I was wondering how does cached image cleanup happen in this implementation. I saw a automaticdelete lambda but Im not exactly sure what this does. If I delete an image in my original source bucket, do I need to delete the corresponding folder of images in the image optimization bucket as well?

alexei commented 1 month ago

From the README:

The transformed image is stored in S3 with a lifecycle policy that deletes it after a certain duration (default of 90 days) to reduce the storage cost.

If cached images are deleted automatically after some time, I wouldn't worry about cleaning up when source object gets deleted, unless it was a business requirement (privacy etc.)

achrafsouk commented 1 month ago

I would like to hear from you your use case before answering. Let's assume that the generated image was corrupted or that you have completely changed the original image and tou want to reflect it to users. In this case, you need to remove all generated images of the image (under same folder), and then invalidate the cache.

If you update an image, but publish it with a new URL (versioning approach), no action is needed from your side. The old image variants will fall of the CloudFront cache, and the corresponding assets in the generated image folder will be deleted by the S3 lifecycle policy to avoid incurring cost.

RahulBirCodes commented 1 month ago

@achrafsouk As of right now, I change the original image in the bucket, so I guess I would need to remove all the generated images and invalidate the cache. However, I'd prefer not to do that so I think Ill switch it so that I publish it with a new url and delete the old image from the source bucket. Thanks!

achrafsouk commented 1 month ago

Awesome!