whatyouhide/testing_aws_in_elixir

Not working

Opened this issue · 1 comments

feld commented

Tried to use your blog post advice to permit mocking of AWS requests, kept failing.

Cloned this repo so I could confirm I wasn't crazy:

> mix test

18:26:29.603 [error] GenServer ExAws.Config.AuthCache terminating
** (RuntimeError) Instance Meta Error: {:error, %{reason: :timeout}}

You tried to access the AWS EC2 instance meta, but it could not be reached.
This happens most often when trying to access it from your local computer,
which happens when environment variables are not set correctly prompting
ExAws to fallback to the Instance Meta.

Please check your key config and make sure they're configured correctly:

For Example:
\`\`\`
ExAws.Config.new(:s3)
ExAws.Config.new(:dynamodb)
\`\`\`

    (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:27: ExAws.InstanceMeta.request/2
    (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:64: ExAws.InstanceMeta.instance_role_credentials/1
    (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:72: ExAws.InstanceMeta.security_credentials/1
    (ex_aws 2.2.10) lib/ex_aws/config/auth_cache.ex:116: ExAws.Config.AuthCache.refresh_auth_now/2
    (ex_aws 2.2.10) lib/ex_aws/config/auth_cache.ex:45: ExAws.Config.AuthCache.handle_call/3
    (stdlib 3.17.2) gen_server.erl:721: :gen_server.try_handle_call/4
    (stdlib 3.17.2) gen_server.erl:750: :gen_server.handle_msg/6
    (stdlib 3.17.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.286.0>): {:refresh_auth, %{access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role], host: "localhost", http_client: ExAws.Request.Hackney, json_codec: Jason, normalize_path: true, port: 4566, region: "us-east-1", retries: [max_attempts: 10, base_backoff_in_ms: 10, max_backoff_in_ms: 10000], scheme: "http", secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]}}
State: ExAws.Config.AuthCache
Client #PID<0.286.0> is alive

    (stdlib 3.17.2) gen.erl:233: :gen.do_call/4
    (elixir 1.13.4) lib/gen_server.ex:1027: GenServer.call/3
    (ex_aws 2.2.10) lib/ex_aws/config.ex:98: ExAws.Config.retrieve_runtime_value/2
    (elixir 1.13.4) lib/stream.ex:572: anonymous fn/4 in Stream.map/2
    (elixir 1.13.4) lib/enum.ex:4475: Enumerable.List.reduce/3
    (elixir 1.13.4) lib/stream.ex:1719: Enumerable.Stream.do_each/4
    (elixir 1.13.4) lib/enum.ex:1112: Enum.find/3
    (ex_aws 2.2.10) lib/ex_aws/config.ex:85: anonymous fn/2 in ExAws.Config.retrieve_runtime_config/1
    (stdlib 3.17.2) maps.erl:410: :maps.fold_1/3
    (ex_aws 2.2.10) lib/ex_aws/config.ex:41: ExAws.Config.new/2
    (ex_aws 2.2.10) lib/ex_aws.ex:71: ExAws.request/2
    (ex_aws 2.2.10) lib/ex_aws.ex:82: ExAws.request!/2
    test/testing_aws_in_elixir_test.exs:28: TestinAWSInElixirTest."test download_file_from_s3!/3"/1
    (ex_unit 1.13.4) lib/ex_unit/runner.ex:500: ExUnit.Runner.exec_test/1
    (stdlib 3.17.2) timer.erl:166: :timer.tc/1
    (ex_unit 1.13.4) lib/ex_unit/runner.ex:451: anonymous fn/4 in ExUnit.Runner.spawn_test_monitor/4

18:26:37.616 [error] GenServer ExAws.Config.AuthCache terminating
** (RuntimeError) Instance Meta Error: {:error, %{reason: :timeout}}

You tried to access the AWS EC2 instance meta, but it could not be reached.
This happens most often when trying to access it from your local computer,
which happens when environment variables are not set correctly prompting
ExAws to fallback to the Instance Meta.

Please check your key config and make sure they're configured correctly:

For Example:
\`\`\`
ExAws.Config.new(:s3)
ExAws.Config.new(:dynamodb)
\`\`\`

    (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:27: ExAws.InstanceMeta.request/2
    (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:64: ExAws.InstanceMeta.instance_role_credentials/1
    (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:72: ExAws.InstanceMeta.security_credentials/1
    (ex_aws 2.2.10) lib/ex_aws/config/auth_cache.ex:116: ExAws.Config.AuthCache.refresh_auth_now/2
    (ex_aws 2.2.10) lib/ex_aws/config/auth_cache.ex:45: ExAws.Config.AuthCache.handle_call/3
    (stdlib 3.17.2) gen_server.erl:721: :gen_server.try_handle_call/4
    (stdlib 3.17.2) gen_server.erl:750: :gen_server.handle_msg/6
    (stdlib 3.17.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.291.0>): {:refresh_auth, %{access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role], host: "localhost", http_client: ExAws.Request.Hackney, json_codec: Jason, normalize_path: true, port: 4566, region: "us-east-1", retries: [max_attempts: 10, base_backoff_in_ms: 10, max_backoff_in_ms: 10000], scheme: "http", secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]}}
State: ExAws.Config.AuthCache
Client #PID<0.291.0> is alive

    (stdlib 3.17.2) gen.erl:233: :gen.do_call/4
    (elixir 1.13.4) lib/gen_server.ex:1027: GenServer.call/3
    (ex_aws 2.2.10) lib/ex_aws/config.ex:98: ExAws.Config.retrieve_runtime_value/2
    (elixir 1.13.4) lib/stream.ex:572: anonymous fn/4 in Stream.map/2
    (elixir 1.13.4) lib/enum.ex:4475: Enumerable.List.reduce/3
    (elixir 1.13.4) lib/stream.ex:1719: Enumerable.Stream.do_each/4
    (elixir 1.13.4) lib/enum.ex:1112: Enum.find/3
    (ex_aws 2.2.10) lib/ex_aws/config.ex:85: anonymous fn/2 in ExAws.Config.retrieve_runtime_config/1
    (stdlib 3.17.2) maps.erl:410: :maps.fold_1/3
    (ex_aws 2.2.10) lib/ex_aws/config.ex:41: ExAws.Config.new/2
    (ex_aws 2.2.10) lib/ex_aws.ex:105: ExAws.stream!/2
    test/testing_aws_in_elixir_test.exs:18: anonymous fn/0 in TestinAWSInElixirTest."test download_file_from_s3!/3"/1
    (ex_unit 1.13.4) lib/ex_unit/on_exit_handler.ex:143: ExUnit.OnExitHandler.exec_callback/1
    (ex_unit 1.13.4) lib/ex_unit/on_exit_handler.ex:129: ExUnit.OnExitHandler.on_exit_runner_loop/0


  1) test download_file_from_s3!/3 (TestinAWSInElixirTest)
     test/testing_aws_in_elixir_test.exs:9
     ** (exit) exited in: GenServer.call(ExAws.Config.AuthCache, {:refresh_auth, %{access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role], host: "localhost", http_client: ExAws.Request.Hackney, json_codec: Jason, normalize_path: true, port: 4566, region: "us-east-1", retries: [max_attempts: 10, base_backoff_in_ms: 10, max_backoff_in_ms: 10000], scheme: "http", secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]}}, 30000)
         ** (EXIT) an exception was raised:
             ** (RuntimeError) Instance Meta Error: {:error, %{reason: :timeout}}

     You tried to access the AWS EC2 instance meta, but it could not be reached.
     This happens most often when trying to access it from your local computer,
     which happens when environment variables are not set correctly prompting
     ExAws to fallback to the Instance Meta.

     Please check your key config and make sure they're configured correctly:

     For Example:
     \`\`\`
     ExAws.Config.new(:s3)
     ExAws.Config.new(:dynamodb)
     \`\`\`

                 (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:27: ExAws.InstanceMeta.request/2
                 (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:64: ExAws.InstanceMeta.instance_role_credentials/1
                 (ex_aws 2.2.10) lib/ex_aws/instance_meta.ex:72: ExAws.InstanceMeta.security_credentials/1
                 (ex_aws 2.2.10) lib/ex_aws/config/auth_cache.ex:116: ExAws.Config.AuthCache.refresh_auth_now/2
                 (ex_aws 2.2.10) lib/ex_aws/config/auth_cache.ex:45: ExAws.Config.AuthCache.handle_call/3
                 (stdlib 3.17.2) gen_server.erl:721: :gen_server.try_handle_call/4
                 (stdlib 3.17.2) gen_server.erl:750: :gen_server.handle_msg/6
                 (stdlib 3.17.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
     code: ExAws.request!(ExAws.S3.put_bucket("test-bucket", "us-west-2"))
     stacktrace:
       (elixir 1.13.4) lib/gen_server.ex:1030: GenServer.call/3
       (ex_aws 2.2.10) lib/ex_aws/config.ex:98: ExAws.Config.retrieve_runtime_value/2
       (elixir 1.13.4) lib/stream.ex:572: anonymous fn/4 in Stream.map/2
       (elixir 1.13.4) lib/enum.ex:4475: Enumerable.List.reduce/3
       (elixir 1.13.4) lib/stream.ex:1719: Enumerable.Stream.do_each/4
       (elixir 1.13.4) lib/enum.ex:1112: Enum.find/3
       (ex_aws 2.2.10) lib/ex_aws/config.ex:85: anonymous fn/2 in ExAws.Config.retrieve_runtime_config/1
       (stdlib 3.17.2) maps.erl:410: :maps.fold_1/3
       (ex_aws 2.2.10) lib/ex_aws/config.ex:41: ExAws.Config.new/2
       (ex_aws 2.2.10) lib/ex_aws.ex:71: ExAws.request/2
       (ex_aws 2.2.10) lib/ex_aws.ex:82: ExAws.request!/2
       test/testing_aws_in_elixir_test.exs:28: (test)



Finished in 16.0 seconds (0.00s async, 16.0s sync)
1 test, 1 failure

Randomized with seed 501057

It seems to me like it could be an issue with accessing AWS somehow.

  1. Do you have your AWS credentials set up?
  2. Can you paste the output of ExAws.Config.new(:s3)?