Erlang SNS amazon erlcloud 发布失败并出现超时错误

Erlang SNS amazon erlcloud publish fails with timeout error

我正在尝试使用 erlcloud 根据从客户端接收到的 endpointArn 向移动设备发送推送通知。我能够通过 Java 应用程序成功推送通知。但是如果我尝试使用 erlang,同样的东西,它会给出超时错误。以下是代码示例。

Config = erlcloud_sns:new(<<"Access Key">>,<<"secret Key">>,<<"sns.us-west-2.amazonaws.com">>).
erlcloud_sns:publish(target,<<"arn:aws:sns:us-west-2:2315XXXXXX:endpoint/GCM/testapp/XXXXXXX-fe9a-304e-aa52-XXXXXXXX">>,<<"ok">>,undefined,[],Config).

最后一条语句显示以下错误。

** exception error: {sns_error,{socket_error,timeout}}
 in function  erlcloud_sns:sns_xml_request/3 (src/erlcloud_sns.erl, line 670)
 in call from erlcloud_sns:publish/6 (src/erlcloud_sns.erl, line 471)

access_key、secret_key、Host 和 endpointArn 的相同值来自 Java 程序。

简答

将您的参数更改为字符串,它将起作用。即:

Config = erlcloud_sns:new("Access Key","secret Key","sns.us-west-2.amazonaws.com"). erlcloud_sns:publish(target,"arn:aws:sns:us-west-2:2315XXXXXX:endpoint/GCM/testapp/XXXXXXX-fe9a-304e-aa52-XXXXXXXX","ok",undefined,[],Config).

长答案

erlcloud 需要所有参数的字符串。不幸的是,它不是在存储之前验证配置值,而是存储您提供的任何内容,然后在尝试使用它时失败。在这种情况下,它无法识别凭据 here (because the guard function is_list returns false). In the end, it falls back to getting credentials from ECS (here),在那里遇到超时并导致您看到的错误。