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:
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 geo.eu-west-1.amazonaws.com 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 places.geo.eu-west-1.amazonaws.com, 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?
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 = "https://places.geo.eu-west-1.amazonaws.com"
json_body = %{"Text" => address, "MaxResults" => 1} |> Jason.encode!()
path
|> HTTPoison.post!(json_body, headers())
|> handle_response()
end
defp headers do
[{"Content-Type", "application/json"}, {"Authorization", basic_auth()}]
end
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"
}
end
defp handle_response(%HTTPoison.Response{status_code: code, body: body}) do
%{
code: code,
body: Jason.decode!(body)
}
end
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!