aws / aws-record-ruby

Official repository for the aws-record gem, an abstraction for Amazon DynamoDB.
Apache License 2.0
321 stars 42 forks source link

Seahorse::Client::NetworkingError (SSL_connect returned=1 errno=0 state=error: wrong version number) #101

Closed linkyndy closed 4 years ago

linkyndy commented 4 years ago

Hello, I am trying to run a table migration on a local instance of DynamoDB (using the Docker image). Here's what I am trying:

irb(main):035:0> client = Aws::DynamoDB::Client.new(region: 'local', access_key_id: 'foobar', secret_access_key: 'foobar
')
irb(main):036:0> migration = Aws::Record::TableMigration.new(Model, client: client)
irb(main):037:1* migration.create!(
irb(main):038:2*   provisioned_throughput: {
irb(main):039:2*     read_capacity_units: 5,
irb(main):040:2*     write_capacity_units: 2
irb(main):041:1*   },
irb(main):042:2* global_secondary_index_throughput: {
irb(main):043:3*   gsi: {
irb(main):044:3*     read_capacity_units: 3,
irb(main):045:3*     write_capacity_units: 1
irb(main):046:2*   }
irb(main):047:1* }
irb(main):048:0> )
Seahorse::Client::NetworkingError (SSL_connect returned=1 errno=0 state=error: wrong version number)

The local instance of DynamoDB is running, since I am able to query it from my terminal.

I can't tell what is wrong here. Would appreciate any guidance!

mullermp commented 4 years ago

What version of J/Ruby are you using? That appears to be an OpenSSL related issue, where "wrong version" would refer to the underlying SSL/TLS protocol. Check your OpenSSL version on your Docker image and use a newer Ruby version perhaps? Search around for OpenSSL "wrong version number" to start.

Are you referring to this image? https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.Docker.html

linkyndy commented 4 years ago

Hey @mullermp, thanks for your reply. I am using Ruby 2.7.0 and OpenSSL 1.1.1 (on MacOS Catalina). Yes, I am referring to the DynamoDB Docker image.

mullermp commented 4 years ago

I'm thinking that your DynamoDB local service is not using TLSv1.2. Could you try starting aws-v3.rb with the -v option or adding http_wire_trace: true to the Client options, and pasting the output?

linkyndy commented 4 years ago

@mullermp here's the output with http_wire_trace: true:

irb(main):060:0> client = Aws::DynamoDB::Client.new(region: 'local', access_key_id: 'sdfsdf', secret_access_key: 'sfddsf', http_wire_trace: true)
irb(main):061:0> migration = Aws::Record::TableMigration.new(Peek::Item, client: client)
irb(main):062:1* migration.create!(
irb(main):063:2*   provisioned_throughput: {
irb(main):064:2*     read_capacity_units: 5,
irb(main):065:2*     write_capacity_units: 2
irb(main):066:1*   },
irb(main):067:2* global_secondary_index_throughput: {
irb(main):068:3*   format_created_index: {
irb(main):069:3*     read_capacity_units: 3,
irb(main):070:3*     write_capacity_units: 1
irb(main):071:2*   }
irb(main):072:1* }
irb(main):073:0> )
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
opening connection to localhost:8000...
opened
starting SSL for localhost:8000...
Conn close because of connect error SSL_connect returned=1 errno=0 state=error: wrong version number
Traceback (most recent call last):
       16: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/aws-sdk-core/plugins/transfer_encoding.rb:24:in `call'
       15: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/aws-sdk-core/plugins/signature_v4.rb:66:in `call'
       14: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/aws-sdk-core/json/error_handler.rb:8:in `call'
       13: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-dynamodb-1.45.0/lib/aws-sdk-dynamodb/plugins/crc32_validation.rb:30:in `call'
       12: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/seahorse/client/plugins/content_length.rb:15:in `call'
       11: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/seahorse/client/net_http/handler.rb:47:in `call'
       10: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/seahorse/client/net_http/handler.rb:73:in `transmit'
        9: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/seahorse/client/net_http/handler.rb:121:in `session'
        8: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/seahorse/client/net_http/connection_pool.rb:97:in `session_for'
        7: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.91.1/lib/seahorse/client/net_http/connection_pool.rb:299:in `start_session'
        6: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/2.7.0/delegate.rb:83:in `method_missing'
        5: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/2.7.0/net/http.rb:938:in `start'
        4: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/2.7.0/net/http.rb:943:in `do_start'
        3: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/2.7.0/net/http.rb:1009:in `connect'
        2: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/2.7.0/net/protocol.rb:44:in `ssl_socket_connect'
        1: from /Users/andrei/.rbenv/versions/2.7.0/lib/ruby/2.7.0/net/protocol.rb:44:in `connect_nonblock'
Seahorse::Client::NetworkingError (SSL_connect returned=1 errno=0 state=error: wrong version number)

Not sure how shall I take it from here 🤔

linkyndy commented 4 years ago

It seems that by default, the DynamoDB client was trying to use https when constructing the endpoint, and since DynamoDB Local uses http, it caused the above error.

I've fixed it by manually providing the endpoint when creating the client:

client = Aws::DynamoDB::Client.new(region: 'local', access_key_id: 'sdfsdf', secret_access_key: 'sfddsf', endpoint: 'http://localhost:8000')
mullermp commented 4 years ago

Ah ok! That makes sense that there was some mismatch on OpenSSL version (the mismatch was that there was no cipher in http). I'm glad you were able to figure it out.