繁体   English   中英

Ruby gem使CloudFront分发无效?

[英]Ruby gem to invalidate CloudFront Distribution?

我已经尝试了所有可以在Google和Stackoverflow上找到的gem,它们似乎都已过时且无法维护,那么从Ruby禁用CloudFront发行版的最简单方法是什么?

https://rubygems.org/gems/aws-sdk

具体来说是cloudfront模块:

https://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFront.html

如果您具有正确的IAM角色等设置,这应该为您提供对Cloudfront资源的完全CLI控制。

这是我们最终用来使整个缓存无效的小脚本:

require 'aws-sdk-cloudfront'

cf = Aws::CloudFront::Client.new(
  access_key_id: ENV['FOG_AWS_ACCESS_KEY_ID'],
  secret_access_key: ENV['FOG_AWS_SECRET_ACCESS_KEY'],
  region: ENV['FOG_REGION']
)

resp = cf.create_invalidation({
  distribution_id: ENV['FOG_DISTRIBUTION_ID'], # required
  invalidation_batch: { # required
    paths: { # required
      quantity: 1, # required
      items: ["/*"],
    },
    caller_reference: DateTime.now.to_s, # required
  },
})

if resp.is_a?(Seahorse::Client::Response)
  puts "Invalidation #{resp.invalidation.id} has been created. Please wait about 60 seconds for it to finish."
else
  puts "ERROR"
end 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM