ex-aws / ex_aws

A flexible, easy to use set of clients AWS APIs for Elixir
https://hex.pm/packages/ex_aws
MIT License
1.28k stars 527 forks source link

Sub-libraries not swapping JSON codec or using region in config #616

Closed foggy1 closed 5 years ago

foggy1 commented 5 years ago

Environment

Elixir 1.7.4 (compiled with Erlang/OTP 21)

Current behavior

I have the following in my config

config :ex_aws, :our_app,
  region: "us-west-1",
  json_codec: Jason

and I have tried adding and removing the following as well

config :ex_aws_lambda, :our_app,
  region: "us-west-2",
  json_codec: Jason

When I make an ExAws.request() with any given ExAws.Lambda function, it tries to go to the default us-east-1, ignoring both configs.

Additionally, if I do not have Poison installed, AWS requests (when I specific us-west-2 in the request) fail since they try to use Poison instead of Jason.

I have had a similar problem with the ex_aws_cloudwatch library on a separate project.

Expected behavior

I expect the config to be respected since the docs indicate that it should be. I initially thought this was an issue in the sub-libraries but the error ends up falling back in the core ExAws operation library.

** (UndefinedFunctionError) function Poison.encode!/1 is undefined (module Poison is not available)
    Poison.encode!(%{the map i was trying to encode})
    (ex_aws) lib/ex_aws/request.ex:19: ExAws.Request.request/6
    (ex_aws) lib/ex_aws/operation/json.ex:49: ExAws.Operation.ExAws.Operation.JSON.perform/2

If the issue is in the sub-libraries, it must just be a matter of propagating the config changes downwards. I would be happy to help with this if someone can point me in the right direction.

It's not hard to install Poison or to type us-west-2 in my ExAws.request fields, but it seems silly that I should have to install two JSON libraries or specifiy a single region all over the place.

benwilson512 commented 5 years ago

Hey @foggy1 sorry to hear you're having issues.

config :ex_aws, :our_app,
  region: "us-west-1",
  json_codec: Jason

Why are you doing config this way? Just do:

config :ex_aws,
  region: "us-west-1",
  json_codec: Jason
foggy1 commented 5 years ago

Ugh, thank you.