E.Z.
E.Z.

Reputation: 159

How to use Fog Library to create CDN in AWS

I am new in the DevOps world and my company uses Fog library to deploy EC2 instances for our Dev Environment. One of my company's products needs a CDN and I am trying to figure out how I can automate CDN using the same Fog Library.

I found info at fog.io and here is the code I put in makeCDN.rb (with a .sh wrapper to deploy it).

#!/usr/bin/ruby
require 'fog'

# create a connection to the service
cdn = Fog::CDN.new({

 :provider               => 'AWS',
 :aws_access_key_id      => 'fake_key_id',
 :aws_secret_access_key  => '2345fake_access_key6789'
})

cdn.post_distribution({
  'CustomOrigin' => {
    'DNSName'               => 'hostname.domain.org', #example name
    'HTTPPort'              => '80',
    'OriginProtocolPolicy'  => 'match-viewer',
    'DefaultRootObject'     => '/',
    'Enabled'               => 'true',
  }

})

So, I am unsure what I am doing wrong but the error I am getting is:

/home/eztheog/.rvm/gems/ruby-1.9.3-p547@fogDev/gems/excon-0.38.0/lib/excon/middlewares/expects.rb:10:in 
`response_call': Expected(201) <=> Actual(400 Bad Request) (Excon::Errors::BadRequest)
response => #<Excon::Response:0x00000001d73b78 @data={:body=>"<?xml version=\"1.0\"?>\n<ErrorResponse 
xmlns=\"http://cloudfront.amazonaws.com/doc/2010-11-01/\"><Error>
<Type>Sender</Type><Code>MalformedXML</Code><Message>1 validation error
 detected: Value null at 'distributionConfig.enabled' failed to satisfy
 constraint: Member must not be null</Message></Error>
<RequestId>c2b33cda-abee-11e4-8115-b584e1255c70</RequestId>
</ErrorResponse>", :headers=>{"x-amzn-RequestId"=>"c2b33cda-abee-11e4-8115-b584e1255c70",
 "Content-Type"=>"text/xml", "Content-Length"=>"371", "Date"=>"Tue, 03
 Feb 2015 21:51:07 GMT"}, :status=>400, :remote_ip=>"205.251.242.229",
 :local_port=>39733, :local_address=>"10.100.6.203"}, @body="<?xml 
version=\"1.0\"?>\n<ErrorResponse 
xmlns=\"http://cloudfront.amazonaws.com/doc/2010-11-01/\"><Error>
<Type>Sender</Type><Code>MalformedXML</Code><Message>1 validation error 
detected: Value null at 'distributionConfig.enabled' failed to satisfy
 constraint: Member must not be null</Message></Error>
<RequestId>c2b33cda-abee-11e4-8115-b584e1255c70</RequestId>
</ErrorResponse>", @headers={"x-amzn-RequestId"=>"c2b33cda-abee-11e4-
8115-b584e1255c70", "Content-Type"=>"text/xml", "Content-Length"=>"371",
 "Date"=>"Tue, 03 Feb 2015 21:51:07 GMT"}, @status=400, 
@remote_ip="205.251.242.229", @local_port=39733, 
@local_address="10.100.6.203">

I have found information here but am unsure how to parse the info into the ruby file.

There seems to be little blog stuff that I can find to figure out how to do this.

Can anyone point me the right direction?

Upvotes: 0

Views: 109

Answers (1)

E.Z.
E.Z.

Reputation: 159

I found this gist that explains the context.

So, the RubyDoc.info link (in question) said that the Enabled Boolean was an Option. But, in AWS it is not (or so it seems based on the error I got).

But, to resolve this, the :Enabled => true has to be OUTSIDE of the cdn.distribution block.

Hope this helps anyone who is looking for this in the future!

Also, this might be a BUG because the Fog library says that this feature is OPTIONAL but it seems mandatory by AWS.

Upvotes: 1

Related Questions