Calling UpdateThing returns 504 Gateway Timeout when using AWS C++ SDK

172 views Asked by At

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());
}
1

There are 1 answers

0
R Jeans On

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