AWS location geocoding returning error

Hi, I am trying to use AWS to geocode with input, but I am getting errors, I think there is something wrong with my syntax, but I cannot figure out what:

My code:

  1. client = AWS.Client.create(System.fetch_env!(“AWS_ACCESS_KEY_ID”), System.fetch_env!
    (“AWS_SECRET_ACCESS_KEY”), “eu-west-1”)
  2. AWS.Location.search_place_index_for_text(client, “site_addresses”, “2 Water Lane”)

“site_addresses” is my index name and the address I am searching is “2 Water Lane”

I am following the docs:

This is the error I am getting back:

Thanks! :smiley:

FWIW, posting log output in triple-backticks (```) will format it nicely and is more readable than a screenshot.

In this case the important part is at the very end of the line that wraps:

and is_map(payload)

The AWS request machinery expects a map shaped like the payload in the AWS docs:

    "Text": "Any Town",
    "MaxResults": 10

Your second line could be instead:

AWS.Location.search_place_index_for_text(client, “site_addresses”, %{"Text" => “2 Water Lane”})
1 Like

Thank you! I am no longer getting that error
The problem is, I am now getting this error back:
{:error, :nxdomain}
I have tried googling and searching in the docs - I cannot figure out if it is the syntax or my config…

My reading of the code in AWS.Request.build_host is that it’ll produce a hostname like for these requests, but that host doesn’t exist!

That’s why you’re seeing an NXDOMAIN error from the network stack.

The Amazon documentation says the correct host for a place search in eu-west-1 is, which does resolve to an address.

I don’t see a straightforward way to override that behavior, short of passing a function in endpoint somehow. Maybe it’s a bug in the code generator?

Thanks a lot for your help!
I’m going to try with diff domains and see what happens; if the others don’t work it is probably a bug :frowning:


Just following this, I am trying to send the request as a url because the built in function does not work

Can anyone help with the authorisation headers - I am unsure how to format the access key id, secret access key and region, and then pass them through as authorisation.

These are the docs I was looking at:

This is my code so far:

def get_coordinates(address) do
  path = ""
  json_body = %{"Text" =>  address, "MaxResults" => 1} |> Jason.encode!()

  |>!(json_body, headers())
  |> handle_response()

defp headers do
    [{"Content-Type", "application/json"}, {"Authorization", basic_auth()}]

defp basic_auth do
      access_key_id: System.fetch_env!("AWS_ACCESS_KEY_ID"),
      secret_access_key : System.fetch_env!("AWS_SECRET_ACCESS_KEY"),
      region: "eu-west-1"

defp handle_response(%HTTPoison.Response{status_code: code, body: body}) do
    code: code,
    body: Jason.decode!(body)

The root cause was that we were not considering the “host prefix” some services require it. The problem is now fixed in version 0.13.0 of the AWS package. Thanks @shirawebill for reporting this! :slight_smile:

1 Like