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

Cloudfront always returns "X-Cache: Miss from cloudfront"

Open tap-andy opened this issue 7 years ago • 4 comments

I've noticed that my Cloudfront distribution for my serverless image handler setup is always returning the header:

X-Cache: Miss from cloudfront

Which means it'll always be passing through to the image handler and wasting time. I have sent the same request many times and it always returns this. I have tried both options for Object Caching in the Cloudfront behaviour settings (Use Origin Cache Headers, Customize) but neither works.

image

Not sure what other information to give other than I've manually added this line of code to index.js - https://github.com/awslabs/serverless-image-handler/pull/151/commits/3d408e3b3a7f43f10a017d401c1c1e423a02d557 becaues I also couldn't get the cache-control header working. I was successful with getting this passed through to the browser and hoped it would work with the "Use Origin Cache Headers" option for Object Caching in Cloudfront but to resolve the X-Cache: Miss issue but sadly not.

tap-andy avatar Oct 28 '19 15:10 tap-andy

New info:

I am using a custom domain for my image handler. The caching works if I use the original Cloudfront domain, but not if I use my custom domain.

tap-andy avatar Nov 04 '19 09:11 tap-andy

Solved:

I have my custom domain set up incorrectly. I had attached the custom domain to the API Gateway distribution created by CloudFormation rather than to the actual CloudFront distribution. After switching this around, I now get CloudFront cache hits as expected.

tap-andy avatar Nov 04 '19 16:11 tap-andy

We are closing this issue, but please feel free to open the issue again if you any other support.

beomseoklee avatar Feb 06 '20 21:02 beomseoklee

Solved:

I have my custom domain set up incorrectly. I had attached the custom domain to the API Gateway distribution created by CloudFormation rather than to the actual CloudFront distribution. After switching this around, I now get CloudFront cache hits as expected.

I'm doing like u said, after I set up my custom domain from cloudflare point to API gateway, here is the link: https://api.cloudimagewall.xyz/401x0/toi-la-nguoi-choi-duy-nhat-dang-nhap/chapter-2/1620552516056-0_1.jpg but I still get x-cache miss Do I need to point my domain to cloudfront too ? can someone help me :( I stuggle so hard on this

(Note: I using cloudflare to prevent hotlink protection by cloudflare FireWall )

onggiabayluon avatar May 10 '21 02:05 onggiabayluon