0

Recently I have started to use the AWS C++ SDK with some success. Those calls that are based on HTTPS GET are working fine. For the IoT REST API I am able to create Things and ListThings.

However when I am calling the UpdateThing request, the call hangs and on timeout I get a AWS 504 gateway timeout error.

I have tried a number of things but to no avail. There seems to be few published examples to help me decode the issue.

The AWS DEBUG log output is here:

[DEBUG] 2017-01-03 22:08:42 AWSClient [0x7fff755d1000] Request Successfully signed
[DEBUG] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] Attempting to acquire curl connection.
[DEBUG] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] No current connections available in pool. Attempting to create new connections.
[DEBUG] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] attempting to grow pool size by 2
[INFO] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] Pool successfully grown by 2
[INFO] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] Connection has been released. Continuing.
[DEBUG] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] Returning connection handle 0x7f90bc00da00
[DEBUG] 2017-01-03 22:08:42 CurlHttpClient [0x7fff755d1000] Obtained connection handle 0x7f90bc00da00
[DEBUG] 2017-01-03 22:09:42 CurlHttpClient [0x7fff755d1000] Returned http response code 504
[DEBUG] 2017-01-03 22:09:42 CurlHttpClient [0x7fff755d1000] Releasing curl handle 0x7f90bc00da00
[DEBUG] 2017-01-03 22:09:42 CurlHandleContainer [0x7fff755d1000] Releasing curl handle 0x7f90bc00da00
[DEBUG] 2017-01-03 22:09:42 CurlHandleContainer [0x7fff755d1000] Notified waiting threads.
[DEBUG] 2017-01-03 22:09:42 AWSClient [0x7fff755d1000] Request returned error. Attempting to generate appropriate error codes from response
[ERROR] 2017-01-03 22:09:42 AWSClient [0x7fff755d1000] No response body.  Response code: 504

The code is:

Aws::IoT::Model::UpdateThingRequest request;
Aws::IoT::Model::AttributePayload payload;

payload.AddAttributes("manufacturer",manufacturer);
payload.AddAttributes("product",product);
payload.AddAttributes("type",type);
payload.SetMerge(true);

request
     .WithThingName(name)
     .WithAttributePayload(payload);

auto outcome = _client->UpdateThing(request);

if (outcome.IsSuccess()) {
    log.info("Sucess");
} else {
    log.info("Error: %s: %s",outcome.GetError().GetExceptionName().c_str(),
            outcome.GetError().GetMessage().c_str());
}
R Jeans
  • 31
  • 1
  • No response body? That seems unexpected. I wonder if that's a fake error code, locally generated... – Michael - sqlbot Jan 04 '17 at 03:39
  • I believe the lack of a response body is due to the timeout. I need to look more closely at how the POST interaction is implemented in the SDK. – R Jeans Jan 04 '17 at 07:46
  • Actually it looks like it is related to the way the library is handling rest PATCH calls. POST method works fine. It seems to be down to the AWS REST service waiting for the PATCH body and it not being sent by the client. – R Jeans Jan 04 '17 at 10:39

1 Answers1

1

My issue seemed to be that way that the curl Mac OS X library (7.52.1) was treating the PATCH request. By default it was not calling the registered data function (registered via CURLOPT_READFUNCTION).

I solved this by patching the CurlHttpClient.cpp file to add the CURLOPT_POST option for a PATCH request.

https://github.com/aws/aws-sdk-cpp/pull/401

R Jeans
  • 31
  • 1