-
Couldn't load subscription status.
- Fork 1.2k
Description
I've been testing an automated process where I create a S3 bucket and then a CloudFront distribution. Executing my script would give the following error:
aws-sdk-1.8.1.1/lib/aws/core/client.rb:318:in `return_or_raise': The origin server does not exist or is not valid. (AWS::CloudFront::Errors::InvalidOrigin)
Code:
require 'rubygems'
require 'aws-sdk'
cf = AWS::CloudFront.new
cloudfront_config = {
:distribution_config => {
:caller_reference => Time.now.nsec.to_s,
:aliases => {
:quantity => 0
},
:default_root_object => "index.html",
:origins => {
:quantity => 1,
:items => [
{
:id => "BUCKETNAME",
:domain_name => "BUCKETNAME.s3.amazonaws.com"
}
]
},
:default_cache_behavior => {
:target_origin_id => "#{d}",
:forwarded_values => {
:query_string => false
},
:trusted_signers => {
:enabled => false,
:quantity => 0
},
:viewer_protocol_policy => "allow-all",
:min_ttl => 900
},
:cache_behaviors => {
:quantity => 0
},
:comment => "A new CloudFront distribution has been created for BUCKETNAME.",
:logging => {
:enabled => false,
:bucket => "",
:prefix => ""
},
:enabled => true
}
}
cloudfront_distribution = cf.client.create_distribution(cloudfront_config)That kept giving the InvalidOrigin error until I stumbled upon this: https://bitbucket.org/jmurty/jets3t/issue/150/update-to-api-version-2012-05-05. So, I made it work by modifying distribution_config.origins.items to look like this:
:items => [
{
:id => "BUCKETNAME",
:domain_name => "BUCKETNAME.s3.amazonaws.com",
:s3_origin_config => {
:origin_access_identity => ""
}
}
]I'm bringing this up, because the documentation indicated "s3_origin_config" as optional (see here: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/CloudFront/Client.html#create_distribution-instance_method), so I left it off and then had quite a time trying to figure out what was wrong.