Lambda@Edge CloudFront Returning 301 on Cache-Hit

时间:2019-04-16 23:51:38

标签: aws-lambda amazon-cloudfront

I'm using CloudFront and Lambda@Edge to dynamically resize, store, and return images from an S3 bucket. I largely followed this tutorial on the AWS website: https://aws.amazon.com/blogs/networking-and-content-delivery/resizing-images-with-amazon-cloudfront-lambdaedge-aws-cdn-blog/

In the viewer request I'm rewriting the URL if a size parameter is set to /optimized/size/format/image.jpg

Then in the origin response I'm checking to see if the origin returns a 404 and if it does then I get the original key, return the object from S3, resize the image and store the optimized image in S3. Then I return a 301 redirect once the upload process is done.

The image is being saved successfully in S3, but I've noticed even if the image exists in S3. I still get a 404 response from S3, despite the image existing already.

Thanks for the help in advance!

0 个答案:

没有答案