AWS cloudfront不会更新S3中的文件更新

时间:2021-05-17 23:02:14

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.

我在S3上使用我的文件在cloudfront中创建了一个发行版。它工作正常,我的所有文件都可用。但今天我在S3上更新了我的文件并试图通过Cloudfront访问它们,但它仍然提供了旧文件。

What am I missing ?

我错过了什么?

5 个解决方案

#1


You should invalidate your objects in CloudFront distribution cache. Back in the old days you'd have to do it 1 file at a time, now you can do it wildcard, e.g. /images/*

您应该在CloudFront分配缓存中使对象无效。回到过去,你必须一次做1个文件,现在你可以做通配符,例如/图片/*

https://aws.amazon.com/about-aws/whats-new/2015/05/amazon-cloudfront-makes-it-easier-to-invalidate-multiple-objects/

#2


How to change the Cache-Control max-age via the AWS S3 Console:

如何通过AWS S3控制台更改Cache-Control max-age:

  • Navigate to the file whose Cache-Control you would like to change.
  • 导航到要更改其Cache-Control的文件。

  • Check the box next to the file name (it will turn blue)
  • 选中文件名旁边的框(它将变为蓝色)

  • On the top right click Properties
  • 在右上角单击“属性”

  • Click Metadata
  • If you do not see a Key named Cache-Control, then click Add more metadata.
  • 如果没有看到名为Cache-Control的Key,则单击Add more metadata。

  • Set the Key to Cache-Control set the Value to max-age=0 (where 0 is the number of seconds you would like the file to remain in the cache). You can replace 0 with whatever you want.
  • 将Key设置为Cache-Control,将Value设置为max-age = 0(其中0是您希望文件保留在缓存中的秒数)。你可以用你想要的任何东西替换0。

AWS cloudfront不会更新S3中的文件更新

#3


Thanks tedder42 and Chris Heald

谢谢tedder42和Chris Heald

I was able to reduce the cache duration in my origin i.e. s3 object and deliver the files more instantly then what it was by default 24 hours. for some of my other distribution I also set forward all headers to origin in which cloudfront doesn't cache anything and sends all request to origin.

我能够减少我的源中的缓存持续时间,即s3对象,并且比默认情况下24小时更快地传送文件。对于我的其他一些发行版,我还将所有标题都设置为源,其中cloudfront不会缓存任何内容并将所有请求发送到源。

thanks.

#4


Please refer to this answer this may help you.

请参考这个答案,这可能对您有所帮助。

What's the difference between Cache-Control: max-age=0 and no-cache?

Cache-Control有什么区别:max-age = 0和no-cache?

Adding a variable Cache-Control to 0 in the header to the selected file in S3AWS cloudfront不会更新S3中的文件更新

在S3中将标头中的变量Cache-Control添加到所选文件中

#5


I also had this issue and solved it by using versioning (not the same as S3 versioning). Here is a comprehensive link to using versioning with cloudfront

我也有这个问题并通过使用版本控制解决了它(与S3版本不同)。以下是使用cloudfront版本控制的综合链接

Invalidating Files In summary:

总结文件无效:

When you upload a new file or files to your S3 bucket, change the version, and update your links as appropriate. From the documentation the benefit of using versioning vs. invalidating (the other way to do this) is that there is no additional charge for making CloudFront refresh by version changes whereas there is with invalidation. If you have hundreds of files this may be problematic, but its possible that by adding a version to your root directory, or default root object (if applicable) it wouldn't be a problem. In my case, I have an SPA, all I have to do is change the version of my default root object (index.html to index2.html) and it instantly updates on CloudFront.

将新文件或文件上载到S3存储桶时,请更改版本,并根据需要更新链接。从文档中可以看出,使用版本控制与使用无效(另一种方法)的好处是,通过版本更改使CloudFront刷新没有额外费用,而存在失效。如果您有数百个文件,这可能会有问题,但可能通过向根目录添加版本或默认根对象(如果适用),这可能不是问题。在我的情况下,我有一个SPA,我所要做的就是更改我的默认根对象的版本(index.html到index2.html),它立即在CloudFront上更新。

#1


You should invalidate your objects in CloudFront distribution cache. Back in the old days you'd have to do it 1 file at a time, now you can do it wildcard, e.g. /images/*

您应该在CloudFront分配缓存中使对象无效。回到过去,你必须一次做1个文件,现在你可以做通配符,例如/图片/*

https://aws.amazon.com/about-aws/whats-new/2015/05/amazon-cloudfront-makes-it-easier-to-invalidate-multiple-objects/

#2


How to change the Cache-Control max-age via the AWS S3 Console:

如何通过AWS S3控制台更改Cache-Control max-age:

  • Navigate to the file whose Cache-Control you would like to change.
  • 导航到要更改其Cache-Control的文件。

  • Check the box next to the file name (it will turn blue)
  • 选中文件名旁边的框(它将变为蓝色)

  • On the top right click Properties
  • 在右上角单击“属性”

  • Click Metadata
  • If you do not see a Key named Cache-Control, then click Add more metadata.
  • 如果没有看到名为Cache-Control的Key,则单击Add more metadata。

  • Set the Key to Cache-Control set the Value to max-age=0 (where 0 is the number of seconds you would like the file to remain in the cache). You can replace 0 with whatever you want.
  • 将Key设置为Cache-Control,将Value设置为max-age = 0(其中0是您希望文件保留在缓存中的秒数)。你可以用你想要的任何东西替换0。

AWS cloudfront不会更新S3中的文件更新

#3


Thanks tedder42 and Chris Heald

谢谢tedder42和Chris Heald

I was able to reduce the cache duration in my origin i.e. s3 object and deliver the files more instantly then what it was by default 24 hours. for some of my other distribution I also set forward all headers to origin in which cloudfront doesn't cache anything and sends all request to origin.

我能够减少我的源中的缓存持续时间,即s3对象,并且比默认情况下24小时更快地传送文件。对于我的其他一些发行版,我还将所有标题都设置为源,其中cloudfront不会缓存任何内容并将所有请求发送到源。

thanks.

#4


Please refer to this answer this may help you.

请参考这个答案,这可能对您有所帮助。

What's the difference between Cache-Control: max-age=0 and no-cache?

Cache-Control有什么区别:max-age = 0和no-cache?

Adding a variable Cache-Control to 0 in the header to the selected file in S3AWS cloudfront不会更新S3中的文件更新

在S3中将标头中的变量Cache-Control添加到所选文件中

#5


I also had this issue and solved it by using versioning (not the same as S3 versioning). Here is a comprehensive link to using versioning with cloudfront

我也有这个问题并通过使用版本控制解决了它(与S3版本不同)。以下是使用cloudfront版本控制的综合链接

Invalidating Files In summary:

总结文件无效:

When you upload a new file or files to your S3 bucket, change the version, and update your links as appropriate. From the documentation the benefit of using versioning vs. invalidating (the other way to do this) is that there is no additional charge for making CloudFront refresh by version changes whereas there is with invalidation. If you have hundreds of files this may be problematic, but its possible that by adding a version to your root directory, or default root object (if applicable) it wouldn't be a problem. In my case, I have an SPA, all I have to do is change the version of my default root object (index.html to index2.html) and it instantly updates on CloudFront.

将新文件或文件上载到S3存储桶时,请更改版本,并根据需要更新链接。从文档中可以看出,使用版本控制与使用无效(另一种方法)的好处是,通过版本更改使CloudFront刷新没有额外费用,而存在失效。如果您有数百个文件,这可能会有问题,但可能通过向根目录添加版本或默认根对象(如果适用),这可能不是问题。在我的情况下,我有一个SPA,我所要做的就是更改我的默认根对象的版本(index.html到index2.html),它立即在CloudFront上更新。