ExAws不参与生产发布(Phoenix / Arc / ExAws)

时间:2016-07-09 03:10:05

标签: amazon-s3 elixir phoenix-framework

我一直在尝试为头像创建一个上传器,但我一直面临一些问题,代码在dev上完美运行,但在生产版本上,我收到了这个错误:

=SUPERVISOR REPORT==== 8-Jul-2016::22:35:41 ===
     Supervisor: {local,'Elixir.ExAws.Supervisor'}
     Context:    child_terminated
     Reason:     {#{'__exception__' => true,
                    '__struct__' => 'Elixir.Poison.SyntaxError',
                    message => <<"Unexpected token: <">>,
                    token => <<"<">>},
                  [{'Elixir.Poison.Parser','parse!',2,
                       [{file,"lib/poison/parser.ex"},{line,56}]},
                   {'Elixir.Poison','decode!',2,
                       [{file,"lib/poison.ex"},{line,83}]},
                   {'Elixir.ExAws.InstanceMeta',security_credentials,1,
                       [{file,"lib/ex_aws/instance_meta.ex"},{line,16}]},
                   {'Elixir.ExAws.Config.AuthCache',refresh_config,2,
                       [{file,"lib/ex_aws/config/auth_cache.ex"},{line,37}]},
                   {'Elixir.ExAws.Config.AuthCache',handle_call,3,
                       [{file,"lib/ex_aws/config/auth_cache.ex"},{line,27}]},
                   {gen_server,try_handle_call,4,
                       [{file,"gen_server.erl"},{line,615}]},
                   {gen_server,handle_msg,5,
                       [{file,"gen_server.erl"},{line,647}]},
                   {proc_lib,init_p_do_apply,3,
                       [{file,"proc_lib.erl"},{line,247}]}]}
     Offender:   [{pid,<0.2009.0>},
                  {id,'Elixir.ExAws.Config.AuthCache'},
                  {mfargs,
                      {'Elixir.ExAws.Config.AuthCache',start_link,
                          [[{name,'Elixir.ExAws.Config.AuthCache'}]]}},
                  {restart_type,permanent},
                  {shutdown,5000},
                  {child_type,worker}]

22:35:41.624 [error] Ranch protocol #PID<0.2011.0> (:cowboy_protocol) of listener MyApp.Endpoint.HTTP terminated
** (exit) exited in: GenServer.call(ExAws.Config.AuthCache, {:refresh_config, %ExAws.S3{config: %{access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role], host: %{"ap-northeast-1" => 
"s3-ap-northeast-1.amazonaws.com", "ap-southeast-1" => "s3-ap-southeast-1.amazonaws.com", "ap-southeast-2" => "s3-ap-southeast-2.amazonaws.com", "eu-central-1" => "s3-eu-central-1.amazonaws.c
om", "eu-west-1" => "s3-eu-west-1.amazonaws.com", "sa-east-1" => "s3-sa-east-1.amazonaws.com", "us-east-1" => "s3.amazonaws.com", "us-west-1" => "s3-us-west-1.amazonaws.com", "us-west-2" => "
s3-us-west-2.amazonaws.com"}, http_client: ExAws.Request.HTTPoison, json_codec: Poison, region: "us-east-1", scheme: "https://", secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :insta
nce_role]}, service: :s3}}, 5000)
    ** (EXIT) an exception was raised:
        ** (Poison.SyntaxError) Unexpected token: <
            (poison) lib/poison/parser.ex:56: Poison.Parser.parse!/2
            (poison) lib/poison.ex:83: Poison.decode!/2
            (ex_aws) lib/ex_aws/instance_meta.ex:16: ExAws.InstanceMeta.security_credentials/1
            (ex_aws) lib/ex_aws/config/auth_cache.ex:37: ExAws.Config.AuthCache.refresh_config/2
            (ex_aws) lib/ex_aws/config/auth_cache.ex:27: ExAws.Config.AuthCache.handle_call/3
            (stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
            (stdlib) gen_server.erl:647: :gen_server.handle_msg/5
            (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

感谢。

1 个答案:

答案 0 :(得分:1)

您的堆栈跟踪说Poison是ExAws使用的dep,无法解码json。如果您检查进行该调用的模块(lib/ex_aws/instance_meta.ex,您可以阅读here),您会发现它与Amazon通信以检查您的凭据。

最可能的是您的配置不正确,并且亚马逊正在向您发送格式为XML或HTML的错误消息(均以<开头)。

ExAws配置依赖于env vars,因此这也可能是它适用于dev的原因,但不适用于生产。