aws / aws-sdk-ruby

The official AWS SDK for Ruby.
https://aws.amazon.com/sdk-for-ruby/
Apache License 2.0
3.58k stars 1.23k forks source link

"Unexpected list element termination" when trying to call update_distribution method for CloudFront #1954

Closed SirRawlins closed 5 years ago

SirRawlins commented 5 years ago

This seems to be a regression (issues #1067, #774 and #99), but I'm getting the same error with aws-sdk-cloudfront v1.11.0 (with Ruby 2.5.1).

I've only just started working with the SDK so can't be sure when this was introduced.

Looking at the previous issues, and conversations on StackOverflow it seems to be a recurring issue, whereby the SDK doesn't like { :quantity => 0, :items => [] } in the payload. If quantity is 0, the items key should not be included.

Failing test case:

distribution_id = "..." # CF Distribution ID here
cloudfront = Aws::CloudFront::Client.new

resp = cloudfront.get_distribution_config({
  id: distribution_id,
})

cloudfront.update_distribution({
  id: distribution_id,
  distribution_config: resp.distribution_config,
  if_match: resp.etag
})

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

Work Around:

I'm currently able to work around this error by deleting the the [:origin_groups][:items] key from the distribution_config payload, who's value is currently an empty array.

awood45 commented 5 years ago

Can you provide the http_wire_trace output (anonymizing specific values like the distribution is fine and even encouraged)? It's hard to tell from this if it's the SDK not properly marshalling the request, or if this is a quirk on the service side.

SirRawlins commented 5 years ago

@awood45 sure thing Alex. Here's the http_wire_trace generated from the code example.

opening connection to cloudfront.amazonaws.com:443... opened starting SSL for cloudfront.amazonaws.com:443... SSL established <- "PUT /2018-11-05/distribution/XXX/config HTTP/1.1\r\nContent-Type: \r\nAccept-Encoding: \r\nUser-Agent: aws-sdk-ruby3/3.44.2 ruby/2.5.1 x86_64-darwin15 aws-sdk-cloudfront/1.11.0\r\nIf-Match: E25PI0SI26B0B0\r\nHost: cloudfront.amazonaws.com\r\nX-Amz-Date: 20190110T105559Z\r\nX-Amz-Content-Sha256: 759e108068b7c2c3eb552f3149b7ff1a7d87248e3339449dfacf3d88a5f586b4\r\nAuthorization: AWS4-HMAC-SHA256 Credential=XXX SignedHeaders=host;if-match;x-amz-content-sha256;x-amz-date, Signature=c6db1d97c2e9c97d1223bd58045f54ca8fd137a7e522bef6fc867ec8cc0d7a9d\r\nContent-Length: 3224\r\nAccept: /\r\n\r\n" -> "HTTP/1.1 400 Bad Request\r\n" -> "x-amzn-RequestId: 506c5e55-14c6-11e9-89dc-75337560d9a2\r\n" -> "Content-Type: text/xml\r\n" -> "Content-Length: 283\r\n" -> "Date: Thu, 10 Jan 2019 10:55:59 GMT\r\n" -> "Connection: close\r\n" -> "\r\n" reading 283 bytes... -> "" -> "<?xml version=\"1.0\"?>\n<ErrorResponse xmlns=\"http://cloudfront.amazonaws.com/doc/2018-11-05/\">SenderMalformedInputUnexpected list element termination506c5e55-14c6-11e9-89dc-75337560d9a2" read 283 bytes Conn close Traceback (most recent call last): 16: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in block in require_with_bootsnap_lfi' 15: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:inrequire' 14: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/railties-4.2.11/lib/rails/commands.rb:17:in <main>' 13: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:39:inrun_command!' 12: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:68:in console' 11: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/railties-4.2.11/lib/rails/commands/console.rb:9:instart' 10: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/railties-4.2.11/lib/rails/commands/console.rb:110:in start' 9: from (irb):7 8: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/aws-sdk-cloudfront-1.11.0/lib/aws-sdk-cloudfront/client.rb:3712:inupdate_distribution' 7: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/aws-sdk-core-3.44.2/lib/seahorse/client/request.rb:70:in send_request' 6: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/aws-sdk-core-3.44.2/lib/seahorse/client/plugins/response_target.rb:23:incall' 5: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/aws-sdk-core-3.44.2/lib/aws-sdk-core/plugins/response_paging.rb:10:in call' 4: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/aws-sdk-core-3.44.2/lib/aws-sdk-core/plugins/param_converter.rb:24:incall' 3: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/aws-sdk-core-3.44.2/lib/aws-sdk-core/plugins/idempotency_token.rb:17:in call' 2: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/aws-sdk-core-3.44.2/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:incall' 1: from /Users/robertrawlins/.rvm/gems/ruby-2.5.1/gems/aws-sdk-core-3.44.2/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call' Aws::CloudFront::Errors::MalformedInput (Unexpected list element termination)

Let me know if there's anything else I can do to help narrow down what's going on.

srchase commented 5 years ago

@SirRawlins

This is caused by the CloudFront API returning a self-closed tag in the get_distribution_config response:

<OriginGroups>
  <Quantity>0</Quantity>
  <Items/>
</OriginGroups>

That output is an invalid input for the the update_distribution_config operation. I've opened a request for the CloudFront Service Team to investigate.

SirRawlins commented 5 years ago

Excellent stuff. Thanks so much. 👍

On Mon, 14 Jan 2019, 17:38 Chase Coalwell <notifications@github.com wrote:

@SirRawlins https://github.com/SirRawlins

This is caused by the CloudFront API returning a self-closed tag in the get_distribution_config response:

0

That output is an invalid input for the the update_distribution_config operation. I've opened a request for the CloudFront Service Team to investigate.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aws/aws-sdk-ruby/issues/1954#issuecomment-454093350, or mute the thread https://github.com/notifications/unsubscribe-auth/AAtiKxrfTT_4ymE0x_wwlrie7nmaegxYks5vDMCOgaJpZM4Z1JJp .

mullermp commented 5 years ago

This appears to be fixed.