If the AWS client is inadvertently created with a nil value for the region, then invoking a resource request will result in a vague {:error, :nxdomain} result.
Example
GIVEN:
The env var AWS_REGION is not set, but AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are.
WHEN:
This code is executed:
aws = AWS.Client.create(
System.get_env("AWS_ACCESS_KEY_ID"),
System.get_env("AWS_SECRET_ACCESS_KEY"),
System.get_env("AWS_REGION")
)
{:ok, msg} = AWS.Lambda.delete_function(aws, "my-lambda-function", %{})
THEN:
The following error occurs:
(MatchError) no match of right hand side value: {:error, :nxdomain}
Notes
After some investigation, I discovered that the request sent to hackney was specifying the host as: lambda..amazonaws.com
This malformed host value is built when parts contains ["lambda", nil, "amazonaws.com"] in the build_final_endpoint function here:
|
joined = Enum.join(parts, ".") |
build_final_endpoint is called here:
|
build_final_endpoint( |
|
[ |
|
to_string(metadata[:host_prefix]) <> metadata.endpoint_prefix, |
|
client.region, |
|
endpoint |
|
], |
|
build_options |
|
) |
Resolution?
If the AWS API always requires a region subdomain for these endpoints, it would be helpful if this library had some sort of validation to ensure the presence of client.region and produce a clear error message when it's missing.
If the AWS client is inadvertently created with a
nilvalue for the region, then invoking a resource request will result in a vague{:error, :nxdomain}result.Example
GIVEN:
The env var
AWS_REGIONis not set, butAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYare.WHEN:
This code is executed:
THEN:
The following error occurs:
Notes
After some investigation, I discovered that the request sent to hackney was specifying the host as:
lambda..amazonaws.comThis malformed host value is built when
partscontains["lambda", nil, "amazonaws.com"]in thebuild_final_endpointfunction here:aws-elixir/lib/aws/request.ex
Line 253 in 8e23feb
build_final_endpointis called here:aws-elixir/lib/aws/request.ex
Lines 227 to 234 in 8e23feb
Resolution?
If the AWS API always requires a region subdomain for these endpoints, it would be helpful if this library had some sort of validation to ensure the presence of
client.regionand produce a clear error message when it's missing.