How can I update files on Amazon's CDN (CloudFront)?

后端 未结 9 540
情书的邮戳
情书的邮戳 2020-12-30 05:29

Is there any way to update files stored on Amazon CloudFront (Amazon\'s CDN service)? Seems like it won\'t take any update of a file we make (e.g. removing the file and stor

9条回答
  •  一整个雨季
    2020-12-30 05:49

    In ruby, using the fog gem

    AWS_ACCESS_KEY = ENV['AWS_ACCESS_KEY_ID']
    AWS_SECRET_KEY = ENV['AWS_SECRET_ACCESS_KEY']
    AWS_DISTRIBUTION_ID = ENV['AWS_DISTRIBUTION_ID']
    
    conn = Fog::CDN.new(
        :provider => 'AWS',
        :aws_access_key_id => AWS_ACCESS_KEY,
        :aws_secret_access_key => AWS_SECRET_KEY
    )
    
    images = ['/path/to/image1.jpg', '/path/to/another/image2.jpg']
    
    conn.post_invalidation AWS_DISTRIBUTION_ID, images
    

    even on invalidation, it still takes 5-10 minutes for the invalidation to process and refresh on all amazon edge servers

提交回复
热议问题