Search code examples
ruby-on-railsrubyamazon-cloudfrontaws-sdk

What is causing Aws::CloudFront::Errors::MalformedInput: Unexpected list element termination


I'm attempting to create a new AWS Cloudfront Distribution with v2 of the ruby AWS SDK and cannot figure out what is causing this error.

Aws::CloudFront::Errors::MalformedInput: Unexpected list element termination

    client = Aws::CloudFront::Client.new

    resp = client.create_distribution({
        distribution_config: { 
            caller_reference: Time.now.to_i.to_s,
            :aliases => {
                :quantity => 1,
                :items => [Name.generate_name]
            },
            :origins => {
                :quantity => 1,
                :items => [
                    {
                        :id => "#{self.id}-distribution",
                        :domain_name => "example-static.s3-website-us-east-1.amazonaws.com",
                        :origin_path => "/#{self.id}",
                        :custom_headers => {
                            :quantity => 0,
                            :items => []
                        },
                        :custom_origin_config => {
                            :http_port => 80,
                            :https_port => 443,
                            :origin_protocol_policy => "http-only",
                            :origin_ssl_protocols => {
                                :quantity => 3,
                                :items => ["TLSv1","TLSv1.1","TLSv1.2"]
                            }
                        }
                    }
                ]
            },
            :default_cache_behavior => {
                :target_origin_id => "Custom-example-static.s3-website-us-east-1.amazonaws.com/#{self.id}",
                :forwarded_values => {
                    :query_string => true,
                    :cookies => {
                        :forward => "none"
                    },
                    :headers => {
                        :quantity => 1,
                        :items => ["Origin"]
                    }
                },
                :trusted_signers => {
                    :enabled => false,
                    :quantity => 0
                },
                :viewer_protocol_policy => "allow-all",
                :min_ttl => 0,
                :allowed_methods => {
                    :quantity => 3,
                     :items => ["HEAD","GET","OPTIONS"],
                    :cached_methods => {
                        :quantity => 3,
                        :items => ["HEAD","GET","OPTIONS"]
                    }
                },
                :smooth_streaming => false,
                :default_ttl => 86400,
                :max_ttl => 31536000,
                :compress => true
            },
            :cache_behaviors => {
                :quantity => 0
            },
            :custom_error_responses => {
                :quantity => 0
            },
            :comment => "",
            logging: {
                enabled: true, # required
                include_cookies: false, # required
                bucket: "example-logs", # required
                prefix: "#{self.id}", # required
            },              
            :price_class => "PriceClass_100",
            :enabled => true,
            :restrictions => {
                :geo_restriction => {
                    :restriction_type => "none",
                    :quantity => 0
                }
            }
        }
            })

Solution

  • I compared the results I got back from an existing instance with

    client = Aws::CloudFront::Client.new(:http_wire_trace => true)
    resp = client.get_distribution_config({
        :id => '<ID>'
    })
    

    Changing the payload from

    :custom_headers => {
        :quantity => 0,
        :items => []
    },
    

    to

    :custom_headers => {
        :quantity => 0
    },
    

    seemed to fix the same error message for me.