Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS cloudfront not updating on update of files in S3

I created a distribution in cloudfront using my files on S3. It worked fine and all my files were available. But today I updated my files on S3 and tried to access them via Cloudfront, but it still gave old files.

What am I missing ?

like image 658
Jigar Tank Avatar asked May 10 '15 17:05

Jigar Tank


People also ask

How long does it take for CloudFront to update S3?

Short description. By default, CloudFront caches a response from Amazon S3 for 24 hours (Default TTL of 86,400 seconds). If your request lands at an edge location that served the Amazon S3 response within 24 hours, then CloudFront uses the cached response. This happens even if you updated the content in Amazon S3.

How do I refresh CloudFront content?

Right click your distribution. Select "Get Cloudfront invalidation list" Then select "Create" to create a new invalidation list. Select the files to invalidate, and click "Invalidate." Wait 5-15 minutes.

How long does CloudFront take to update?

The screen you'll see lists all CloudFront distributions, and includes a Status column, which will update from In Progress to Deployed when your resource is ready to test. Amazon indicates that the process can take as long as 15 minutes.


1 Answers

Just ran into the same issue. At first I tried updating the cache control to be 0 and max-age=0 for the files in my S3 bucket I updated but that didn't work.

What did work was following the steps from @jpaljasma. Here's the steps with some screen shots.

First go to your AWS CloudFront service.

Then click on the CloudFront distrubition you want to invalidate. enter image description here

Click on the invalidations tab then click on "Create Invalidation" which is circled in red. enter image description here

In the "object path" text field, you can list the specific files ie /index.html or just use the wildcard /* to invalidate all. This forces cloudfront to get the latest from everything in your S3 bucket.

Once you filled in the text field click on "Invalidate", after CloudFront finishes invalidating you'll see your changes the next time you go to the web page.

enter image description here

Note: if you want to do it via aws command line interface you can do the following command

aws cloudfront create-invalidation --distribution-id <your distribution id> --paths "/*"

The /* will invalidate everything, replace that with specific files if you only updated a few.

To find the list of cloud front distribution id's you can do this command aws cloudfront list-distributions

Look at these two links for more info on those 2 commands:

https://docs.aws.amazon.com/cli/latest/reference/cloudfront/create-invalidation.html

https://docs.aws.amazon.com/cli/latest/reference/cloudfront/list-distributions.html

like image 101
CAMD_3441 Avatar answered Oct 02 '22 05:10

CAMD_3441