serverless-image-handler icon indicating copy to clipboard operation
serverless-image-handler copied to clipboard

S3 Versioning

Open barth12 opened this issue 2 years ago • 2 comments

I am using the Serverless Image Handler, which utilizes a CloudFront distribution to cache images. My origin S3 buckets have versioning enabled. However, I have encountered an issue where CloudFront does not respect the versionId query parameter and always retrieves the latest version of an image. Or maybe CloudFront respect that but Lambda does not?

I have taken the step of configuring CloudFront to pass the versionId query parameter, but unfortunately, it does not seem to be working as expected. I'm unsure of what I might be missing or if there is something else I need to consider. Could you please provide some guidance or suggestions on how to address this issue?

barth12 avatar May 22 '23 15:05 barth12

@barth12 Serverless Image Handler does not currently support the ability to manage versions of the original image. We will add this to the backlog to review if support might be added.

dougtoppin avatar Dec 03 '23 22:12 dougtoppin

Hi @barth12, This isn't something we currently plan to implement. However, if you'd like to implement it yourself, the following is what I would expect would need to be changed:

  • queryStringBehaviour would need to allow the version query parameter for both cache and originRequestPolicy. Location
  • The ImageHandlerEvent queryStringParameters interface should include version. Location
  • You'd have to extract the version query parameter out of the request in the setup method
    • That value would need to be passed into the getOriginalImage call.
  • In the getOriginalImage call, include the VersionId parameter in the imageLocation object used to make the request. Location
    • It's worth noting that the backend lambda would require the s3:GetObjectVersion permission for that object, though that is included by default in the current version of SIH.

Let me know if that ends up working for you, Simon

simonkrol avatar Feb 13 '24 17:02 simonkrol