Skip to content

Instantly share code, notes, and snippets.

@rbm
Created August 29, 2011 09:27
Show Gist options
  • Save rbm/1178081 to your computer and use it in GitHub Desktop.
Save rbm/1178081 to your computer and use it in GitHub Desktop.
Invalidate CloudFront path using fog
#!/usr/bin/env ruby -w
require 'rubygems'
require 'fog'
require 'pp'
AWS_ACCESS_KEY = ENV['AWS_ACCESS_KEY_ID']
AWS_SECRET_KEY = ENV['AWS_SECRET_ACCESS_KEY']
def get_cf_connection()
return Fog::CDN.new(
:provider => 'AWS',
:aws_access_key_id => AWS_ACCESS_KEY,
:aws_secret_access_key => AWS_SECRET_KEY
)
end
def main(args)
distribution = args[0]
path = args[1]
puts distribution, path
puts 'Establishing CloudFront connection...'
conn = get_cf_connection()
puts "About to invalidate path: #{path} for distribution: #{distribution}"
distro = conn.get_distribution distribution
# puts "Distribution info:"
# puts distro.body
# puts conn.get_invalidation_list(distribution).body
resp = conn.post_invalidation distribution, [path]
puts "Done. Response:"
puts resp.body
end
main(ARGV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment