ExAws Config Overriding Not Applying

I’m trying to make requests using ExAws to SQS queues in different regions using different configs but I’ve come across some behaviour that I don’t understand. Normally, given that the library’s default region is us-east-1, I can do the following:

iex(1)> ExAws.SQS.list_queues() |> ExAws.request

and I get the appropriate response. Let’s say I want to do the same thing for us-west in the same program, this is how I’d go about it:

iex(2)> conf = ExAws.Config.new(:sqs, [region: "us-west-1"])
%{access_key_id: "MY_ACCESS_KEY_ID", host: "sqs.us-west-1.amazonaws.com",
  http_client: ExAws.Request.Hackney, json_codec: Poison, port: 443,
  region: "us-east-1",
  retries: [max_attempts: 10, base_backoff_in_ms: 10, max_backoff_in_ms: 10000],
  scheme: "https://",
  secret_access_key: "MY_SECRET_KEY"}

iex(4)> ExAws.SQS.list_queues() |> ExAws.request(conf)
{:error,
 {:http_error, 403,
  %{code: "SignatureDoesNotMatch", detail: "",
    message: "Credential should be scoped to a valid region, not 'us-east-1'. ",
    request_id: "my_request_id", type: "Sender"}}}

which obviously results in error. What’s interesting to note is that the config returned in ExAws.Config.new/2 has the appropriate host but an incorrect region. This is seen in the following:

iex(4)> conf2 = conf |> Map.merge(%{:region => "us-west-1"})
iex(5)> ExAws.SQS.list_queues() |> ExAws.request(conf2) # returns the correct result

Perhaps I’m misunderstanding how configuration is supposed to work with this library and would appreciate any sort of guidance as to how I’m supposed to achieve my desired outcome.

Thanks!

1 Like

There is quite possibly a bug related to ExAws.Config.new. However in general you don’t need to interact with that function directly, you can just do:

ExAws.SQS.list_queues() |> ExAws.request(region: "us-west-1")
1 Like

Thanks!

1 Like

What version of ExAws are you on? This seems fixed in 2.0.1 at least.

1 Like

Hmmm, I was using 2.0.1 as well. Could I accidentally be overriding the value via other means?

1 Like

Actually can you check 2.0.2? I’m realizing I was actually testing on master, which I have now done a new release with.

1 Like

Still running into the problem:

iex(1)> conf = ExAws.Config.new(:sqs, [region: "us-west-1"])
%{access_key_id: "access_key_id", host: "sqs.us-west-1.amazonaws.com",
  http_client: ExAws.Request.Hackney, json_codec: Poison, port: 443,
  region: "us-east-1",
  retries: [max_attempts: 10, base_backoff_in_ms: 10, max_backoff_in_ms: 10000],
  scheme: "https://",
  secret_access_key: "secret_access_key"}

I actually just realized that my ~/.aws/config is set to the us-east-1 region (and I’m using config credentials with ExAws); however, I think I should still be able to override this?

1 Like

AH! that’s very useful information :slight_smile:

It looks like there is an issue with priority, can you create an issue on ExAws itself, thanks!

1 Like