Skip to content

Instantly share code, notes, and snippets.

@yossale
Created July 28, 2020 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yossale/8cc170ec0f21f222e586c01fc77338a8 to your computer and use it in GitHub Desktop.
Save yossale/8cc170ec0f21f222e586c01fc77338a8 to your computer and use it in GitHub Desktop.
Scalable Webhook - Sample code for the Enqueue function
const AWS = require('aws-sdk')
const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
const queueUrl = process.env.QUEUE_REQUESTSQUEUE01
function isValidMessage(msg) {
console.info(`Verifying message [${msg}]`)
//Do some verification logic here
return true
}
exports.handler = async (event) => {
console.info(`Received event: ${JSON.stringify(event)}`)
if (!isValidMessage(event)) {
console.error(`Invalid message authentication, aborting`)
return {
statusCode: 401
}
}
const msgBody = event.body
var params = {
MessageBody: msgBody,
QueueUrl: queueUrl
};
try {
const res = await sqs.sendMessage(params).promise()
console.info(`Queue message sent: ${JSON.stringify(res)}`)
} catch (e) {
console.error(`Failed to send message to queue`, e)
}
return {
statusCode: 200
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment