Force CloudFront distribution/file update

后端 未结 13 1224
失恋的感觉
失恋的感觉 2020-12-07 07:01

I\'m using Amazon\'s CloudFront to serve static files of my web apps.

Is there no way to tell a cloudfront distribution that it needs to refresh it\'s file or point

13条回答
  •  庸人自扰
    2020-12-07 07:37

    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

提交回复
热议问题