Created
April 24, 2020 11:00
-
-
Save badlands/3170076399f545efbbeead35a799c052 to your computer and use it in GitHub Desktop.
How to send messages on a SQS queue with Node.js
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
// Load the AWS SDK for Node.js | |
var AWS = require('aws-sdk'); | |
// Set the region | |
AWS.config.update({ | |
accessKeyId: '....', | |
secretAccessKey: '....', | |
region: 'eu-central-1' | |
}); | |
// Create an SQS service object | |
var sqs = new AWS.SQS(); | |
const MESSAGE = { | |
"game_api_name": "...", | |
"user_id": 1, | |
"type": "action", | |
"id": "...", | |
"received_at": "2018-05-04T04:03:30Z" | |
}; | |
var params = { | |
DelaySeconds: 10, | |
MessageAttributes: {}, | |
MessageBody: JSON.stringify(MESSAGE), | |
QueueUrl: "...." | |
}; | |
sqs.sendMessage(params, function(err, data) { | |
if (err) { | |
console.log("Error", err); | |
} else { | |
console.log("Success", data.MessageId); | |
} | |
}); | |
// snippet-end:[sqs.JavaScript.messages.sendMessage] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment