GithubHelp home page GithubHelp logo

whatyouhide / testing_aws_in_elixir Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 0.0 5 KB

Support code for the blog post "Testing AWS in Elixir" ๐Ÿ•โ€๐Ÿฆบ

Home Page: https://andrealeopardi.com/posts/testing-aws-in-elixir/

Elixir 100.00%
example-project example-code example-app blog-post-app

testing_aws_in_elixir's Introduction

Testing AWS In Elixir โ€” Accompanying Code

This repository contains the Elixir code to accompany this blog post.

This is a normal Mix project.

To run tests locally, in the root of the repository run:

mix deps.get
mix test

testing_aws_in_elixir's People

Contributors

whatyouhide avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

testing_aws_in_elixir's Issues

Not working

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.