<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">There’s a pretty full clone of the Erlang AWS library in mochi that has a set of unit tests taken from the AWS documentation that you might want to use<div class=""><br class=""></div><div class=""><a href="https://github.com/mochi/mochiweb/tree/master/examples/hmac_api" class="">https://github.com/mochi/mochiweb/tree/master/examples/hmac_api</a></div><div class=""><br class=""></div><div class="">Beware though - the AWS canonically rewrites the URL’s a little bit before signing them so this won’t work out of the box.</div><div class=""><br class=""></div><div class="">G</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 14 avr. 2015 à 08:29, Chandru <<a href="mailto:chandrashekhar.mullaparthi@gmail.com" class="">chandrashekhar.mullaparthi@gmail.com</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On 8 April 2015 at 21:47,<span class="Apple-converted-space"> </span><span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:lloyd@writersglen.com" target="_blank" class="">lloyd@writersglen.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">Hello,<br class=""><br class="">I'm striving to look up books in Amazon's db by ISBN. At first blush it looks easy enough:<br class=""><br class=""><a href="http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_LookupbyISBN.html" target="_blank" class="">http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_LookupbyISBN.html</a><br class=""><br class="">But the last item, Signature, baffles me. Procedure here:<br class=""><br class=""><a href="http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html" target="_blank" class="">http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html</a><br class=""><br class="">I'm fine with this until I hit step 4:<br class=""><br class="">-- Sort parameter/value pairs by byte value --- I can see how to do this manually, but don't know how put Erlang to the task<br class=""><br class="">And I'm really stumped when I hit step 8:<br class=""><br class="">-- Calculate an RFC 2104-compliant HMAC with the SHA256 hash algorithm<br class=""><br class="">Any help? Better yet, does anyone have actual code to make such requests they're willing to share?<br class=""><br class=""></blockquote><div class=""><br class=""></div><div class="">Sorry, quite a late reply here, but better late than never I guess. Here is some sample code I dug out of one of my pet projects.<br class=""><font size="2" class=""><span style="font-family: monospace, monospace;" class=""><br class="">sign_amazon_aws_req(Method, Params) -><br class="">    {ok, {AWS_Access_id, Secret_key}} = application:get_env(my_app, aws_access_credentials),<br class=""><br class="">    Boiler_plate_params =<span class="Apple-converted-space"> </span><br class="">        ["Service=AWSECommerceService",<br class="">         "AWSAccessKeyId=" ++ AWS_Access_id,<br class="">         "AssociateTag=my_associate_tag",<br class="">         "Timestamp=" ++ http_uri:encode(aws_timestamp())<br class="">        ],<br class="">    Params_1       = Params ++ Boiler_plate_params,<br class="">    Req_params     = lists:flatten(string:join(lists:sort(Params_1), "&")),<br class="">    Rest_endpoint  = amazon_rest_endpoint(),<br class="">    Rest_path      = "/onca/xml",<br class="">    String_to_sign = [Method,        "\n",<br class="">                      Rest_endpoint, "\n",<br class="">                      Rest_path,     "\n",<br class="">                      Req_params],<br class="">    Signature = http_uri:encode(<br class="">                  base64:encode_to_string(<br class="">                    crypto:hmac(sha256, Secret_key, String_to_sign))),<br class="">    lists:flatten(["https://" ++ Rest_endpoint ++ Rest_path ++ "?",<br class="">                   Req_params,<br class="">                   "&Signature=", Signature]).<br class=""><br class="">amazon_rest_endpoint() -> "<a href="http://webservices.amazon.co.uk/" class="">webservices.amazon.co.uk</a>".<br class=""><br class="">aws_timestamp() -><br class="">    {{Y, M, D}, {H, Mi, S}} = calendar:universal_time(),<br class="">    lists:flatten(io_lib:format("~p-~s-~sT~s:~s:~sZ",<br class="">                                [Y, two_digits(M), two_digits(D),<br class="">                                 two_digits(H), two_digits(Mi), two_digits(S)])).<br class=""></span><span style="font-family: monospace, monospace;" class=""><br class="">two_digits(X) when X < 10        -> [$0 | integer_to_list(X)];<span class="Apple-converted-space"> </span><br class="">two_digits(X) when is_integer(X) -> integer_to_list(X);<br class="">two_digits([X])                  -> [$0, X];<br class="">two_digits(X)                    -> X.<br class=""></span></font><br class=""><br class=""></div></div></div></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">erlang-questions mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:erlang-questions@erlang.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">erlang-questions@erlang.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://erlang.org/mailman/listinfo/erlang-questions" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://erlang.org/mailman/listinfo/erlang-questions</a></div></blockquote></div><br class=""></div></body></html>