Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save princesslea/9ed6674123f29e1ecaef9b4eb2057f81 to your computer and use it in GitHub Desktop.
Save princesslea/9ed6674123f29e1ecaef9b4eb2057f81 to your computer and use it in GitHub Desktop.
lambda.function
'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