How can I create a signature for AWS in Javascript?

3.1k views Asked by At

I am trying to create the signature for AWS Mechanical Turk, using Node.js, but am having trouble doing so. At the moment I am using the following, but keep getting errors:

CryptoJS.HmacSHA1(service + operation + timestamp, process.env.SECRET_ACCESS_KEY); 

The explanation of the signature is at this link. It states that to create a signature

A request signature, an HMAC, is calculated by concatenating the values of the Service, Operation, and Timestamp parameters, in that order, and then calculating an RFC 2104-compliant HMAC, using the Secret Access Key as the "key." The computed HMAC value should be base64 encoded, and is passed as the value of the Signature request parameter. For more information, go to http://www.faqs.org/rfcs/rfc2104.html.

1

There are 1 answers

0
Thomas On BEST ANSWER

I think this will work for you (I use GetAccountBalance) as a simple example:

<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha1.js"></script>  
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>  
<script>
var service = "AWSMechanicalTurkRequester";
var timestamp = new Date().toISOString();
var operation = "GetAccountBalance";
var secret = "YOURSECRETKEY";
var signature = CryptoJS.HmacSHA1(service + operation + timestamp, secret).toString(CryptoJS.enc.Base64);
</script>