-
Notifications
You must be signed in to change notification settings - Fork 138
Description
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:
Line 253 in 8e23feb
| joined = Enum.join(parts, ".") |
build_final_endpoint is called here:
Lines 227 to 234 in 8e23feb
| 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.