ex_aws
ex_aws copied to clipboard
ExAWS.S3.list_buckets() fails when virtual_host is set to true
Hello,
I'm trying to write some example code to list all S3 buckets when using virtual hosting mode and I'm running into a strange issue. This code causes nxdomain errors:
defmodule ListAllBucketsTest do
use ExUnit.Case
test "list all buckets" do
response = ExAws.S3.list_buckets() |> ExAws.request!()
if response.status_code == 200 do
IO.puts("Buckets:")
for bucket <- response.body.buckets do
IO.puts(bucket.name)
end
else
IO.puts("Error listing buckets")
end
end
end
Here is my config/config.exs file:
import Config
config :ex_aws,
debug_requests: true,
json_codec: Jason,
access_key_id: {:system, "AWS_ACCESS_KEY_ID"},
secret_access_key: {:system, "AWS_SECRET_ACCESS_KEY"}
config :ex_aws, :s3,
scheme: "https://",
host: "s3.amazonaws.com",
region: "us-east-1",
virtual_host: true
This throws errors like this:
12:44:07.729 [debug] ExAws: Request URL: "https://.s3.amazonaws.com/" HEADERS: [{"Authorization", "AWS4-HMAC-SHA256 Credential=hunter2"}, {"host", ".s3.amazonaws.com"}, {"x-amz-date", "20250211T174407Z"}, {"x-amz-content-sha256", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}] BODY: "" ATTEMPT: 7
Disabling virtual host style requests makes this test work.