Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change on S3 object header doesn't impact on CloudFront

Yesterday I went through the objects in a bucket in S3 and added this header:

Cache-Control: max-age=604800

I did it using the change metadata option, since I could apply it easily per folder:

enter image description here

Now if I request the image directly I see the correct header:

Cache-Control: max-age=604800
Date: Fri, 25 May 2018 11:28:53 GMT
ETag: "1abf6cb38c4645f3de14a19beba80019"
Last-Modified: Fri, 25 May 2018 11:11:11 GMT
Server: AmazonS3
x-amz-id-2: qQk8NrWHNCOV5SmLvSQGahvYKuQIkcqQdc2I4Hdm2QLGkhet8cF4n1O+c2HLxhEVl7iBReFSflo=
x-amz-request-id: 97C53C15E86CD3FF

But this is the response when I request the image through CloudFront:

HTTP/1.1 304 Not Modified
Connection: keep-alive
Date: Fri, 25 May 2018 11:28:15 GMT
ETag: "1abf6cb38c4645f3de14a19beba80019"
Server: AmazonS3
Age: 70693
X-Cache: Hit from cloudfront
Via: 1.1 1d7454c76d6ac81147ca3cbd1284c8ae.cloudfront.net (CloudFront)
X-Amz-Cf-Id: CLiExdWbIvxcBFcoND6JYjcKQj54QyQkWl48OyPpUPLupHZl8SPfPQ==

My intention when adding this header was to improve the results on Pingdom for Leverage browser caching, but I still get the urls coming form this bucket through CloudFront listed in that section:

https://d253b1eioa5z7b.cloudfront.net/bc_video_ ... 6_9_576_67de5812-fd82-4476-8b3f-886ad3a4907d.png
https://d253b1eioa5z7b.cloudfront.net/bc_video_ ... 6_9_576_a7ddd1ed-0913-41f6-927e-9db33b582a89.jpg

When I did this same thing to other objects in S3 that I use directly from the website (without CDN) I noticed the effects on the Pingdom results immediately.

Should I wait? Or am I doing something wrong here?

like image 551
moondaisy Avatar asked Nov 07 '22 06:11

moondaisy


1 Answers

The Cache-Control changes you are making in S3 are not updated in CloudFront. To push your updates to CloudFront, you need to update your Web Distribution in CloudFront and change the setting Use Origin Cache Headers (see image).

enter image description here

This is per the AWS documentation for CloudFront that details the values you can specify when updating a CloudFront Web Distribution - under the Object Caching header.

To make this change, use the steps discussed in AWS page with details on how to Update a Web Distribution with the CloudFront console, and pay close attention to the third bullet under step 5: Cache behavior settings. This is where you get to the screen shown above and can make the "Use Origin Cache Header" change.

Try it out and see if your Pingdom results improve.

like image 200
Taterhead Avatar answered Nov 30 '22 11:11

Taterhead