Cannot get ExAws.S3 to work with a bucket outside the default region (us-east-1)

Has anyone been able to get ExAws.S3 to work with a bucket that is not in us-east-1?

I’d like to simply list the contents of a bucket that is in Frankfurt (eu-central-1), and I get this error: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-central-1'

With erlcloud this works fine.

I’m facing this issue with ExAws 2.0.2 and ExAwsS3 2.0.0. Does anyone have any pointers on what I am doing wrong here?

Steps to Reproduce

Create a bucket in the Frankfurt (eu-central-1) region

  • Add some objects to the bucket

  • Try to list the bucket contents by doing a

    ExAws.S3.list_objects("my-bucket-name") |> ExAws.request!

Expected Result

I should see the contents of the bucket.

Actual Results

The following error is seen:

** (ExAws.Error) ExAws Request Error!

{:error, {:http_error, 400, %{body: "<?xml version=\"1.0\"
authorization header is malformed; the region 'us-east-1' is wrong;
expecting 'eu-central-1'</Message><Region>eu-central-1</Region>


{"Server", "AmazonS3"}], status_code: 400}}}

(ex_aws) lib/ex_aws.ex:66: ExAws.request!/2

Additional Information

My config.exs looks like this:


config :ex_aws,
  access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, {:awscli, "prod", 30}, :instance_role],
  secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, {:awscli, "prod", 30}, :instance_role],
  region: "eu-central-1"

config :ex_aws, :s3,
  scheme: "https://",
  host: "",
  region: "eu-central-1"

I’ve got a project running with ex_aws_s3 2.0.2, on the eu-west-1 region, and it works fine. In the config.exs I only specify this (access key and secret are taken automatically from the ENV)

config :ex_aws,
  region: System.get_env("AWS_REGION")

Since you’re using a cli config have you double checked if you have a default region set there?
I haven’t used ExawsS3 but did use the dynamo one connecting to that region without problems.

I always see folks setting the host and scheme manually and I’m really confused about why. None of the :s3 config these is necessary, it’ll inherit everything from the main :ex_aws bit. Supplying the region there alone should be enough.

1 Like