Ruby gem使CloudFront Distribution无效?

时间:2017-07-26 11:10:06

标签: ruby amazon-web-services amazon-cloudfront

我已经尝试过我可以在Google和Stackoverflow上找到的所有宝石,它们似乎都已过时且无法维护,那么从Ruby中使CloudFront分配无效的最简单方法是什么?

2 个答案:

答案 0 :(得分:0)

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

特别是cloudfront模块:

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

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

答案 1 :(得分:0)

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

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