class Aws::AcfInterface

Aws::AcfInterface -- RightScale Amazon's CloudFront interface

The AcfInterface class provides a complete interface to Amazon's CloudFront service.

For explanations of the semantics of each call, please refer to Amazon's documentation at developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=211

Example:

acf = Aws::AcfInterface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX')

list = acf.list_distributions #=>
  [{:status             => "Deployed",
    :domain_name        => "d74zzrxmpmygb.6hops.net",
    :aws_id             => "E4U91HCJHGXVC",
    :origin             => "my-bucket.s3.amazonaws.com",
    :cnames             => ["x1.my-awesome-site.net", "x1.my-awesome-site.net"]
    :comment            => "My comments",
    :last_modified_time => Wed Sep 10 17:00:04 UTC 2008 }, ..., {...} ]

distibution = list.first

info = acf.get_distribution(distibution[:aws_id]) #=>
  {:enabled            => true,
   :caller_reference   => "200809102100536497863003",
   :e_tag              => "E39OHHU1ON65SI",
   :status             => "Deployed",
   :domain_name        => "d3dxv71tbbt6cd.6hops.net",
   :cnames             => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
   :aws_id             => "E2REJM3VUN5RSI",
   :comment            => "Woo-Hoo!",
   :origin             => "my-bucket.s3.amazonaws.com",
   :last_modified_time => Wed Sep 10 17:00:54 UTC 2008 }

config = acf.get_distribution_config(distibution[:aws_id]) #=>
  {:enabled          => true,
   :caller_reference => "200809102100536497863003",
   :e_tag            => "E39OHHU1ON65SI",
   :cnames           => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
   :comment          => "Woo-Hoo!",
   :origin           => "my-bucket.s3.amazonaws.com"}

config[:comment] = 'Olah-lah!'
config[:enabled] = false
config[:cnames] << "web3.my-awesome-site.net"

acf.set_distribution_config(distibution[:aws_id], config) #=> true

Constants

API_VERSION
DEFAULT_HOST
DEFAULT_PATH
DEFAULT_PORT
DEFAULT_PROTOCOL

Public Class Methods

bench() click to toggle source
# File lib/acf/acf_interface.rb, line 92
def self.bench
  @@bench
end
bench_service() click to toggle source
# File lib/acf/acf_interface.rb, line 100
def self.bench_service
  @@bench.service
end
bench_xml() click to toggle source
# File lib/acf/acf_interface.rb, line 96
def self.bench_xml
  @@bench.xml
end
connection_name() click to toggle source
# File lib/acf/acf_interface.rb, line 86
def self.connection_name
  :acf_connection
end
new(aws_access_key_id=nil, aws_secret_access_key=nil, params={}) click to toggle source

Create a new handle to a CloudFront account. All handles share the same per process or per thread HTTP connection to CloudFront. Each handle is for a specific account. The params have the following options:

  • :server: CloudFront service host, default: DEFAULT_HOST

  • :port: CloudFront service port, default: DEFAULT_PORT

  • :protocol: 'http' or 'https', default: DEFAULT_PROTOCOL

  • :multi_thread: true=HTTP connection per thread, false=per process

  • :logger: for log messages, default: Rails.logger else STDOUT

  • :cache: true/false: caching for #list_distributions method, default: false.

acf = Aws::AcfInterface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX',
  {:multi_thread => true, :logger => Logger.new('/tmp/x.log')}) #=>  #<Aws::AcfInterface::0xb7b3c30c>
# File lib/acf/acf_interface.rb, line 117
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
  init({:name             => 'ACF',
        :default_host     => ENV['ACF_URL'] ? URI.parse(ENV['ACF_URL']).host : DEFAULT_HOST,
        :default_port     => ENV['ACF_URL'] ? URI.parse(ENV['ACF_URL']).port : DEFAULT_PORT,
        :default_service  => ENV['ACF_URL'] ? URI.parse(ENV['ACF_URL']).path : DEFAULT_PATH,
        :default_protocol => ENV['ACF_URL'] ? URI.parse(ENV['ACF_URL']).scheme : DEFAULT_PROTOCOL},
       aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
       aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
       params)
end

Public Instance Methods

create_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, default_root_object=nil) click to toggle source

Create a new distribution. Returns the just created distribution or Aws::AwsError exception.

acf.create_distribution('bucket-for-k-dzreyev.s3.amazonaws.com', 'Woo-Hoo!', true, ['web1.my-awesome-site.net'] ) #=>
  {:comment            => "Woo-Hoo!",
   :enabled            => true,
   :location           => "https://cloudfront.amazonaws.com/2008-06-30/distribution/E2REJM3VUN5RSI",
   :status             => "InProgress",
   :aws_id             => "E2REJM3VUN5RSI",
   :domain_name        => "d3dxv71tbbt6cd.6hops.net",
   :origin             => "my-bucket.s3.amazonaws.com",
   :cnames             => ["web1.my-awesome-site.net"]
   :last_modified_time => Wed Sep 10 17:00:54 UTC 2008,
   :caller_reference   => "200809102100536497863003"}
# File lib/acf/acf_interface.rb, line 229
def create_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, default_root_object=nil)
  body         = distribution_config_for(origin, comment, enabled, cnames, caller_reference, false, default_root_object)
  request_hash = generate_request('POST', 'distribution', body.strip)
  merge_headers(request_info(request_hash, AcfDistributionParser.new))
end
create_streaming_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, default_root_object=nil) click to toggle source
# File lib/acf/acf_interface.rb, line 235
def create_streaming_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, default_root_object=nil)
  body         = distribution_config_for(origin, comment, enabled, cnames, caller_reference, true, default_root_object)
  request_hash = generate_request('POST', 'streaming-distribution', body.strip)
  merge_headers(request_info(request_hash, AcfDistributionParser.new))
end
delete_distribution(aws_id, e_tag) click to toggle source

Delete a distribution. The enabled distribution cannot be deleted. Returns true on success or Aws::AwsError exception.

acf.delete_distribution('E2REJM3VUN5RSI', 'E39OHHU1ON65SI') #=> true
# File lib/acf/acf_interface.rb, line 340
def delete_distribution(aws_id, e_tag)
  request_hash = generate_request('DELETE', "distribution/#{aws_id}", nil,
                                  'If-Match' => e_tag)
  request_info(request_hash, RightHttp2xxParser.new)
end
delete_streaming_distribution(aws_id, e_tag) click to toggle source
# File lib/acf/acf_interface.rb, line 346
def delete_streaming_distribution(aws_id, e_tag)
  request_hash = generate_request('DELETE', "streaming-distribution/#{aws_id}", nil,
                                  'If-Match' => e_tag)
  request_info(request_hash, RightHttp2xxParser.new)
end
distribution_config_for(origin, comment='', enabled=true, cnames=[], caller_reference=nil, streaming = false, default_root_object=nil) click to toggle source
# File lib/acf/acf_interface.rb, line 241
    def distribution_config_for(origin, comment='', enabled=true, cnames=[], caller_reference=nil, streaming = false, default_root_object=nil)
      rootElement = streaming ? "StreamingDistributionConfig" : "DistributionConfig"
      # join CNAMES
      cnames_str  = ''
      unless cnames.nil? || cnames.empty?
        cnames.to_a.each { |cname| cnames_str += "\n           <CNAME>#{cname}</CNAME>" }
      end
      caller_reference ||= generate_call_reference
      root_ob          = default_root_object ? "<DefaultRootObject>#{config[:default_root_object]}</DefaultRootObject>" : ""
      body             = "        <?xml version="1.0" encoding="UTF-8"?>
        <#{rootElement} xmlns=#{xmlns}>
           <Origin>#{origin}</Origin>
           <CallerReference>#{caller_reference}</CallerReference>
           #{cnames_str.lstrip}
           <Comment>#{AcfInterface::escape(comment.to_s)}</Comment>
           <Enabled>#{enabled}</Enabled>
           #{root_ob}
        </#{rootElement}>
"
    end
get_distribution(aws_id) click to toggle source

Get a distribution's information. Returns a distribution's information or Aws::AwsError exception.

acf.get_distribution('E2REJM3VUN5RSI') #=>
  {:enabled            => true,
   :caller_reference   => "200809102100536497863003",
   :e_tag              => "E39OHHU1ON65SI",
   :status             => "Deployed",
   :domain_name        => "d3dxv71tbbt6cd.6hops.net",
   :cnames             => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
   :aws_id             => "E2REJM3VUN5RSI",
   :comment            => "Woo-Hoo!",
   :origin             => "my-bucket.s3.amazonaws.com",
   :last_modified_time => Wed Sep 10 17:00:54 UTC 2008 }
# File lib/acf/acf_interface.rb, line 278
def get_distribution(aws_id)
  request_hash = generate_request('GET', "distribution/#{aws_id}")
  merge_headers(request_info(request_hash, AcfDistributionParser.new))
end
get_distribution_config(aws_id) click to toggle source

Get a distribution's configuration. Returns a distribution's configuration or Aws::AwsError exception.

acf.get_distribution_config('E2REJM3VUN5RSI') #=>
  {:enabled          => true,
   :caller_reference => "200809102100536497863003",
   :e_tag            => "E39OHHU1ON65SI",
   :cnames           => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
   :comment          => "Woo-Hoo!",
   :origin           => "my-bucket.s3.amazonaws.com"}
# File lib/acf/acf_interface.rb, line 299
def get_distribution_config(aws_id)
  request_hash = generate_request('GET', "distribution/#{aws_id}/config")
  merge_headers(request_info(request_hash, AcfDistributionConfigParser.new))
end
get_streaming_distribution(aws_id) click to toggle source
# File lib/acf/acf_interface.rb, line 283
def get_streaming_distribution(aws_id)
  request_hash = generate_request('GET', "streaming-distribution/#{aws_id}")
  merge_headers(request_info(request_hash, AcfDistributionParser.new))
end
list_distributions() click to toggle source

List distributions. Returns an array of distributions or Aws::AwsError exception.

acf.list_distributions #=>
  [{:status             => "Deployed",
    :domain_name        => "d74zzrxmpmygb.6hops.net",
    :aws_id             => "E4U91HCJHGXVC",
    :cnames             => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
    :origin             => "my-bucket.s3.amazonaws.com",
    :comment            => "My comments",
    :last_modified_time => Wed Sep 10 17:00:04 UTC 2008 }, ..., {...} ]
# File lib/acf/acf_interface.rb, line 204
def list_distributions
  request_hash = generate_request('GET', 'distribution')
  request_cache_or_info :list_distributions, request_hash, AcfDistributionListParser, @@bench
end
list_streaming_distributions() click to toggle source
# File lib/acf/acf_interface.rb, line 209
def list_streaming_distributions
  request_hash = generate_request('GET', 'streaming-distribution')
  request_cache_or_info :list_streaming_distributions, request_hash, AcfStreamingDistributionListParser, @@bench
end
set_distribution_config(aws_id, config) click to toggle source

Set a distribution's configuration (the :origin and the :caller_reference cannot be changed). Returns true on success or Aws::AwsError exception.

config = acf.get_distribution_config('E2REJM3VUN5RSI') #=>
  {:enabled          => true,
   :caller_reference => "200809102100536497863003",
   :e_tag            => "E39OHHU1ON65SI",
   :cnames           => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
   :comment          => "Woo-Hoo!",
   :origin           => "my-bucket.s3.amazonaws.com",
   :default_root_object => 
   }
config[:comment] = 'Olah-lah!'
config[:enabled] = false
acf.set_distribution_config('E2REJM3VUN5RSI', config) #=> true
# File lib/acf/acf_interface.rb, line 321
def set_distribution_config(aws_id, config)
  body         = distribution_config_for(config[:origin], config[:comment], config[:enabled], config[:cnames], config[:caller_reference], false)
  request_hash = generate_request('PUT', "distribution/#{aws_id}/config", body.strip,
                                  'If-Match' => config[:e_tag])
  request_info(request_hash, RightHttp2xxParser.new)
end
set_streaming_distribution_config(aws_id, config) click to toggle source
# File lib/acf/acf_interface.rb, line 328
def set_streaming_distribution_config(aws_id, config)
  body         = distribution_config_for(config[:origin], config[:comment], config[:enabled], config[:cnames], config[:caller_reference], true)
  request_hash = generate_request('PUT', "streaming-distribution/#{aws_id}/config", body.strip,
                                  'If-Match' => config[:e_tag])
  request_info(request_hash, RightHttp2xxParser.new)
end