Created
June 28, 2013 20:40
-
-
Save pwmckenna/5887933 to your computer and use it in GitHub Desktop.
sqs http request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('underscore'); | |
var crypto = require('crypto'); | |
var sign = function (type, queryUrl, parameters) { | |
var raw = type + '\n'; | |
raw += url.parse(queryUrl).host + '\n'; | |
raw += url.parse(queryUrl).path + '\n'; | |
var sorted = _.map(parameters, function (v, k) { | |
return [k, v]; | |
}).sort(function (item1, item2) { | |
return item1[0].localeCompare(item2[0]); | |
}); | |
raw += _.reduce(sorted, function (memo, pair) { | |
return memo + (memo.length ? '&' : '') + pair[0] + '=' + encodeURIComponent(pair[1]); | |
}, ''); | |
var hmac = crypto.createHmac('sha256', SECRET_ACCESS_KEY); | |
hmac.update(raw); | |
return hmac.digest('base64'); | |
}; | |
var parameters = { | |
Action: 'ReceiveMessage', | |
AWSAccessKeyId: ACCESS_KEY_ID, | |
Version: '2012-11-05', | |
Timestamp: new Date().toISOString(), | |
SignatureVersion: 2, | |
SignatureMethod: 'HmacSHA256' | |
}; | |
parameters.Signature = sign('GET', this.queueUrl, parameters); | |
request.get({ | |
url: this.queueUrl, | |
qs: parameters | |
}, function (err, res) {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment