Skip to content

Vague :nxdomain error when client.region is nil #206

@wyattisimo

Description

@wyattisimo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions