Error when I try to reach MTurk
Closed this issue · 10 comments
Hey people,
I am very happy with your package, but something weird happens when I try to reach MTurk:
iex(4)> AWS.MTurk.get_account_balance(client, %{})
** (ArgumentError) argument error
(crypto 4.8.2) crypto.erl:932: :crypto.hmac/3
(aws 0.7.0) lib/aws/request.ex:438: AWS.Request.Internal.signing_key/4
(aws 0.7.0) lib/aws/request.ex:232: AWS.Request.sign_v4/6
(aws 0.7.0) lib/aws/request.ex:40: AWS.Request.request_post/5
If something is wrong with roles, authentication I've seen different errors. This is is caused by Erlang's crypto module and I haven't got the foggiest of what I have done wrong. I am using plug_crypto 1.2.2.
Could you please help me out here
thanks!
Cspr
hey @cskaandorp 👋
can you try to use the version from GitHub?
{:aws, github: "aws-beam/aws-elixir", branch: "master"}
The problem is that :crypto.hmac/3
was removed/renamed in OTP 24. This is fixed, but not released yet.
Thanks for the quick reply! Appreciate it!
Now I am getting this error:
iex(3)> AWS.MTurk.get_account_balance(client, %{})
** (ErlangError) Erlang error: {:badarg, {'mac.c', 179}, 'Bad text'}
(crypto 4.8.2) :crypto.mac_nif(:hmac, :sha256, <<181, 138, 134, 196, 133, 184, 250, 190, 176, 78, 35, 182, 153, 150, 63, 12, 41, 149, 230, 154, 131, 138, 69, 211, 217, 63, 150, 179, 112, 174, 18, 183>>, nil)
(aws 0.7.0) lib/aws/signature.ex:186: AWS.Signature.signing_key/2
(aws 0.7.0) lib/aws/signature.ex:28: AWS.Signature.sign_v4/6
(aws 0.7.0) lib/aws/request.ex:43: AWS.Request.request_post/5
@cskaandorp can you tell me the version of Erlang and Elixir that you have installed?
Erlang/OTP 23 [erts-11.1.6] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.11.3 (compiled with Erlang/OTP 23)
@cskaandorp thanks! I will try to reproduce the error. But before that, can you check if you set the region for your client
? Seems that region
or service
is nil
when we are trying to generated the signing key.
Hey @philss, this is my full code:
iex(2)> client = AWS.Client.create(
...(2)> "XXXXXX",
...(2)> "YYYYYY",
...(2)> "us-east-1"
...(2)> )
iex(3)> client = %AWS.Client{ client | endpoint: "https://mturk-requester-sandbox.us-east-1.amazonaws.com" }
iex(4)> AWS.MTurk.get_account_balance(client, %{})
** (ErlangError) Erlang error: {:badarg, {'mac.c', 179}, 'Bad text'}
(crypto 4.8.2) :crypto.mac_nif(:hmac, :sha256, <<181, 138, 134, 196, 133, 184, 250, 190, 176, 78, 35, 182, 153, 150, 63, 12, 41, 149, 230, 154, 131, 138, 69, 211, 217, 63, 150, 179, 112, 174, 18, 183>>, nil)
(aws 0.7.0) lib/aws/signature.ex:186: AWS.Signature.signing_key/2
(aws 0.7.0) lib/aws/signature.ex:28: AWS.Signature.sign_v4/6
(aws 0.7.0) lib/aws/request.ex:43: AWS.Request.request_post/5
I sure hope I haven't made some stupid mistake. Thanks for getting into this.
Cspr
@cskaandorp I fixed in 07017ef, but I think there is another problem unrelated to the signature. Please try again pointing to master, and then let me know if this works for you :)
Hey @philss
Thanks so much for your effort. I have updated the package:
(anaconda3) ~/Work/mturk_client $ mix deps.update --all
* Updating aws (https://github.com/aws-beam/aws-elixir.git - origin/master)
And it seems there is progression:
iex(7)> AWS.MTurk.get_account_balance(client, %{})
{:error, :nxdomain}
I've tried both with https://mturk-requester-sandbox.us-east-1.amazonaws.com and https://amazonaws.com. I have to admit that I am out of my depth here. Might be that I am barking up the wrong tree with my request.
Cspr
@cskaandorp I tried to set the endpoint to "us-east1.amazonaws.com" and it works! I mean, technically it works, because I don't have access to MTurk.
Can you try this?
client = %{client | endpoint: "us-east-1.amazonaws.com"}
AWS.MTurk.get_account_balance(client, %{})
PS: If you are trying to use the sandbox, then you need to create a new service module with the correct metadata. Something like this:
defmodule AWS.MTurkSandbox do
alias AWS.Client
alias AWS.Request
def metadata do
original = AWS.MTurk.metadata()
%{original | endpoint_prefix: "mturk-requester-sandbox"}
end
def get_account_balance(%Client{} = client, input, options \\ []) do
Request.request_post(client, metadata(), "GetAccountBalance", input, options)
end
end
You can copy the functions from the original MTurk module at lib/aws/generated/mturk.ex
from this project.
ref: https://requester.mturk.com/developer/sandbox
@philss somehow I have missed your post. Thank you, and the rest of the group, so much for your comments, fix and the package. It is all working fine and I am working with it as we speak. Appreciate it!!