Created
October 25, 2017 16:09
-
-
Save princesslea/9ed6674123f29e1ecaef9b4eb2057f81 to your computer and use it in GitHub Desktop.
lambda.function
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
'use strict'; | |
var AWS = require('aws-sdk'); | |
var sqs = new AWS.SQS(); | |
var crypto = require('crypto'); | |
exports.handler = (event, context, callback) => { | |
var client_secret = event.client_secret; | |
delete event.client_secret; | |
//calculate the hash | |
var calculated_hash = crypto.createHmac("sha256", client_secret).update(new Buffer(event.body, "base64")).digest("base64"); | |
//reject the message if the hash doesn't match | |
if (event["X-Shopify-Hmac-SHA256"] != calculated_hash) { | |
console.log("calculated_hash: (" + calculated_hash + ") != X-Shopify-Hmac-SHA256: (" + event["X-Shopify-Hmac-SHA256"] + ")"); | |
return; | |
} | |
sqs.getQueueUrl({ QueueName: event.queue }, function(err, data) { | |
if (err) { | |
console.log('ERR', err); | |
return; | |
} | |
var sqsMessageParams = { | |
MessageBody: JSON.stringify(event), | |
QueueUrl: data.QueueUrl | |
}; | |
sqs.sendMessage(sqsMessageParams, function(err, data) { | |
if (err) { | |
console.log('ERR', err); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment