【问题标题】:Calling UpdateThing returns 504 Gateway Timeout when using AWS C++ SDK使用 AWS C++ SDK 时调用 UpdateThing 返回 504 Gateway Timeout
【发布时间】:2017-01-03 22:18:01
【问题描述】:

最近我开始使用 AWS C++ SDK 并取得了一些成功。那些基于 HTTPS GET 的调用运行良好。对于 IoT REST API,我可以创建 Things 和 ListThings。

但是,当我调用 UpdateThing 请求时,调用挂起,并且在超时时我收到 AWS 504 网关超时错误。

我尝试了很多方法,但都无济于事。似乎很少有已发布的示例可以帮助我解决问题。

AWS DEBUG 日志输出在这里:

[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

代码是:

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

【问题讨论】:

  • 没有响应正文?这似乎出乎意料。我想知道这是否是本地生成的虚假错误代码...
  • 我认为缺少响应正文是由于超时。我需要更仔细地研究一下 SDK 中 POST 交互是如何实现的。
  • 实际上它看起来与库处理其余 PATCH 调用的方式有关。 POST 方法工作正常。这似乎是由于 AWS REST 服务在等待 PATCH 正文,而它没有被客户端发送。

标签: c++ amazon-web-services aws-iot


【解决方案1】:

我的问题似乎是 curl Mac OS X 库 (7.52.1) 正在处理 PATCH 请求。默认情况下,它不调用注册的数据函数(通过 CURLOPT_READFUNCTION 注册)。

我通过修补 CurlHttpClient.cpp 文件为 PATCH 请求添加 CURLOPT_POST 选项解决了这个问题。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-14
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2014-02-08
    • 1970-01-01
    • 2017-09-05
    相关资源
    最近更新 更多