Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iot-data api has incorrect prefix, hence does not work #1064

Closed
SStorm opened this issue Jan 19, 2016 · 3 comments
Closed

iot-data api has incorrect prefix, hence does not work #1064

SStorm opened this issue Jan 19, 2016 · 3 comments
Assignees
Labels
guidance Question that needs advice or information.

Comments

@SStorm
Copy link

SStorm commented Jan 19, 2016

The file aws-sdk-core/apis/iot-data/2015-05-28/api-2.json lists the endpoint for the iot-data API as "data.iot", however this is not a correct endpoint. If you then proceed to attempt to access the given API via the ruby aws sdk with something like:

iot = Aws::IoT::Client.new
endpoint = iot.describe_endpoint.endpoint_address

# Yes, my region for iot resources is eu-west-1
iotd = Aws::IoTDataPlane::Client.new(region: 'eu-west-1', endpoint: 'https://' + endpoint)
iotd.publish({
                 topic: '/test/topic',
                 qos: 1,
                 payload: "{'test':'1'}",
             })

something like this happens:

rake aborted!
Aws::IoTDataPlane::Errors::ForbiddenException: Credential should be scoped to a valid region, not 'us-east-1'. 
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/plugins/param_converter.rb:20:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/plugins/response_target.rb:21:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/request.rb:70:in `send_request'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/base.rb:207:in `block (2 levels) in define_operation_methods'
/Users/romanas/workspace/bootstrap/workspace/playground/Rakefile:32:in `block in <top (required)>'

If I manually edit the api descriptor file and change the endpoint to "iot", I get something like:

Aws::Json::ParseError: 795: unexpected token at 'OK'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/json.rb:30:in `rescue in load'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/json.rb:26:in `load'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/json/parser.rb:17:in `parse'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/rest/response/body.rb:37:in `parse'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/rest/response/body.rb:23:in `apply'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/rest/response/parser.rb:29:in `extract_body'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/rest/response/parser.rb:13:in `apply'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/rest/handler.rb:8:in `block in call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/response.rb:43:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/response.rb:43:in `block in on'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/http/response.rb:139:in `block in on_success'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/http/response.rb:166:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/http/response.rb:166:in `block in listener'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/http/response.rb:130:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/http/response.rb:130:in `on_done'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/http/response.rb:137:in `on_success'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/response.rb:42:in `on'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/rest/handler.rb:8:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/plugins/user_agent.rb:12:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/plugins/endpoint.rb:41:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/plugins/param_validator.rb:21:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/aws-sdk-core/plugins/param_converter.rb:20:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/plugins/response_target.rb:21:in `call'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/request.rb:70:in `send_request'
/Users/romanas/bundler/ruby/1.9.1/gems/aws-sdk-core-2.2.10/lib/seahorse/client/base.rb:207:in `block (2 levels) in define_operation_methods'
/Users/romanas/workspace/bootstrap/workspace/playground/Rakefile:32:in `block in <top (required)>'

Which looks like another bug parsing the response, but is seemingly a successful operation (I get things delivered to the broker).

@awood45
Copy link
Member

awood45 commented Jan 19, 2016

There are a couple things going on here, I'll break it down one at a time.

First, IoT data plane uses an endpoint unique to you, which is the reason that we require you explicitly define an endpoint.

Consider the following:

# Note that you do not need to explicitly define an endpoint.
iot = Aws::IoT::Client.new(region: "us-east-1")

# Throws an ArgumentError
Aws::IoTDataPlane::Client.new(region: "us-east-1")

# Valid
client = Aws::IoTDataPlane::Client.new(
  region: "us-east-1",
  endpoint: "https://#{iot.describe_endpoint.endpoint_address}"
)

@awood45
Copy link
Member

awood45 commented Jan 19, 2016

The second part is a bug between the server and client that I am currently looking at. To help illustrate, let's expand on that last example:

iot = Aws::IoT::Client.new(region: "us-east-1")
client = Aws::IoTDataPlane::Client.new(
  region: "us-east-1",
  endpoint: "https://#{iot.describe_endpoint.endpoint_address}",
  http_wire_trace: true
)
client.publish(topic: "foo")

You'll see something like this:

-> "HTTP/1.1 200 OK\r\n"
-> "content-type: application/json\r\n"
-> "content-length: 2\r\n"
-> "date: Tue, 19 Jan 2016 17:26:10 GMT\r\n"
-> "x-amzn-RequestId: 0827dce3-d9ef-4463-b1f1-40a06d0ead44\r\n"
-> "connection: Keep-Alive\r\n"
-> "\r\n"
reading 2 bytes...
-> "OK"
read 2 bytes

We try to parse the response of OK as JSON, and that's where you get the error. The fix is going to be to make a customization for this service that explicitly checks for this and crafts the appropriate response.

@awood45 awood45 self-assigned this Jan 19, 2016
awood45 added a commit that referenced this issue Jan 19, 2016
Even when the API model did not have an explicitly modeled response
shape, we would attempt to parse the response body. With this change, we
will instead return an empty structure in these cases.

Resolves GitHub Issue #1064
@awood45
Copy link
Member

awood45 commented Jan 19, 2016

We've taken a different approach on this than a customization, but we've confirmed a fix for this. Will go out with the next release.

@awood45 awood45 closed this as completed Jan 19, 2016
awood45 added a commit that referenced this issue Jan 19, 2016
@diehlaws diehlaws added guidance Question that needs advice or information. and removed usage-question labels Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

3 participants