aws-sdk-lua icon indicating copy to clipboard operation
aws-sdk-lua copied to clipboard

Add support for protocol type "query"

Open britzl opened this issue 7 years ago • 4 comments
trafficstars

https://github.com/britzl/aws-sdk-lua/blob/master/aws-sdk/core/request_handlers/query.lua

britzl avatar Nov 05 '18 08:11 britzl

I tried to implement this for SNS and managed to have it working (at least for the request part, handling the response require XML).

I had to remove the content type header (by returning nil in content_type.lua) and add the action to the query (the only way I managed to do that is by changing aws-sdk/sns.lua).

Do you have a better idea on how to fix this (without changing the generator)?

SirLynix avatar Dec 12 '18 11:12 SirLynix

Hi! I'm happy to work with you on this. I've created a branch where I've started working on this:

https://github.com/britzl/aws-sdk-lua/tree/query_support

Two changes I've made:

  • API version is now read from the metadata and set on the settings table: https://github.com/britzl/aws-sdk-lua/blob/query_support/aws-sdk/sns.lua#L3125. Query requests require Action and Version and with this change it is possible to easily read the api version and pass that as a request parameter: https://github.com/britzl/aws-sdk-lua/blob/query_support/aws-sdk/core/request_handlers/query.lua#L13
  • Operation name is passed as a third parameter to request_handlers.from_protocol_and_method(): https://github.com/britzl/aws-sdk-lua/blob/query_support/aws-sdk/sns.lua#L3511. This is then used to create a function closure and pass the name as the first argument: https://github.com/britzl/aws-sdk-lua/blob/query_support/aws-sdk/core/request_handlers.lua#L17-L20 and https://github.com/britzl/aws-sdk-lua/blob/query_support/aws-sdk/core/request_handlers/query.lua#L12. This will have some memory impact but not really that much.

Both of the above changes required a small change to the Mustache template.

I haven't tried any of this yet. Some questions:

  • Should "query" requests really by HTTP POST? The API spec seems to indicate this, but what would the post data be? An empty string?
  • When signing the request I assume it is the entire request URI that should be passed to the V4 signer including all of the query args?

britzl avatar Dec 13 '18 08:12 britzl

I found this about query requests: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Query-Requests.html

It looks like some requests may be GET request as well, although it doesn't look very common in AWS.

It looks like it doesn't expect any POST data actually, in my tests I just didn't send anything. As for v4 signers, I guess it isn't much different from json protocol (as I did manage to make requests using a slightly modified version of the json protocol file for queries).

Your changes look pretty good in my opinion. It's really nice from you to still work on this.

SirLynix avatar Dec 13 '18 09:12 SirLynix

I'll try to find some time to configure and test an AWS service that uses query requests. You're using SNS right?

For XML parsing I think xml2lua will do just fine: https://github.com/manoelcampos/xml2lua

britzl avatar Dec 13 '18 21:12 britzl